feat: add user role field and implement Gravatar fallback for user avatars
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user