feat: add user role field and implement Gravatar fallback for user avatars

This commit is contained in:
Jose Selesan
2026-04-16 20:51:53 -03:00
parent e5002ce440
commit 34a24ce6c9
4 changed files with 86 additions and 4 deletions

View File

@@ -1,13 +1,19 @@
import { createHash } from 'node:crypto';
import type { User } from '@/lib/auth';
import type { UserProfile } from '@repo/api-contract';
function getGravatarUrl(email: string): string {
const hash = createHash('md5').update(email.trim().toLowerCase()).digest('hex');
return `https://www.gravatar.com/avatar/${hash}?d=identicon`;
}
export function getUserProfile(user: User): UserProfile {
return {
id: user.id,
fullName: user.name,
email: user.email,
role: (user as any).role || 'member',
avatarUrl: user.image || null,
avatarUrl: user.image || getGravatarUrl(user.email),
createdAt: user.createdAt,
};
}