feat: add user role field and implement Gravatar fallback for user avatars
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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