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,6 +1,5 @@
import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
// If your Prisma file is located elsewhere, you can change the path
import { openAPI } from 'better-auth/plugins';
import { db } from './prisma';
@@ -19,7 +18,7 @@ export const auth = betterAuth({
enabled: true,
},
trustedOrigins: [process.env.APP_BASE_URL ?? 'http://localhost:5173'],
plugins: [],
plugins: [openAPI()],
});
export type Session = typeof auth.$Infer.Session.session;

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,
};
}