diff --git a/frontend/src/lib/components/header/header-avatar.svelte b/frontend/src/lib/components/header/header-avatar.svelte index fb0b156..c8b7d3d 100644 --- a/frontend/src/lib/components/header/header-avatar.svelte +++ b/frontend/src/lib/components/header/header-avatar.svelte @@ -3,6 +3,7 @@ import * as DropdownMenu from '$lib/components/ui/dropdown-menu'; import WebAuthnService from '$lib/services/webauthn-service'; import userStore from '$lib/stores/user-store'; + import { createSHA256hash } from '$lib/utils/crypto-util'; import { LucideLogOut, LucideUser } from 'lucide-svelte'; const webauthnService = new WebAuthnService(); @@ -11,6 +12,13 @@ ($userStore!.firstName.charAt(0) + $userStore!.lastName?.charAt(0)).toUpperCase() ); + let gravatarURL: string | undefined = $state(); + if ($userStore) { + createSHA256hash($userStore.email).then((email) => { + gravatarURL = `https://www.gravatar.com/avatar/${email}`; + }); + } + async function logout() { await webauthnService.logout(); window.location.reload(); @@ -19,7 +27,8 @@ + > + {initials} diff --git a/frontend/src/lib/components/header/header.svelte b/frontend/src/lib/components/header/header.svelte index fec15eb..9f22a69 100644 --- a/frontend/src/lib/components/header/header.svelte +++ b/frontend/src/lib/components/header/header.svelte @@ -12,7 +12,11 @@
-
+
{#if !isAuthPage} diff --git a/frontend/src/lib/utils/crypto-util.ts b/frontend/src/lib/utils/crypto-util.ts new file mode 100644 index 0000000..45da483 --- /dev/null +++ b/frontend/src/lib/utils/crypto-util.ts @@ -0,0 +1,7 @@ +export async function createSHA256hash(input: string) { + const msgUint8 = new TextEncoder().encode(input); // encode as (utf-8) Uint8Array + const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message + const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array + const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string + return hashHex; +}