mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:53:00 +03:00
feat: add gravatar profile picture integration
This commit is contained in:
@@ -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 @@
|
||||
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger
|
||||
><Avatar.Root>
|
||||
><Avatar.Root class="h-9 w-9">
|
||||
<Avatar.Image src={gravatarURL} />
|
||||
<Avatar.Fallback>{initials}</Avatar.Fallback>
|
||||
</Avatar.Root></DropdownMenu.Trigger
|
||||
>
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
</script>
|
||||
|
||||
<div class=" w-full {isAuthPage ? 'absolute top-0 z-10 mt-4' : 'border-b'}">
|
||||
<div class="mx-auto flex w-full max-w-[1640px] items-center justify-between px-4 md:px-10">
|
||||
<div
|
||||
class="{!isAuthPage
|
||||
? 'max-w-[1640px]'
|
||||
: ''} mx-auto flex w-full items-center justify-between px-4 md:px-10"
|
||||
>
|
||||
<div class="flex h-16 items-center">
|
||||
{#if !isAuthPage}
|
||||
<Logo class="mr-3 h-10 w-10" />
|
||||
|
||||
7
frontend/src/lib/utils/crypto-util.ts
Normal file
7
frontend/src/lib/utils/crypto-util.ts
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user