From 0fbc339447d58a6567af6cc44e018ceae0000a30 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 28 Apr 2025 13:50:28 +0200 Subject: [PATCH] courrier multi account restore compose --- lib/auth.ts | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index c811cddc..2c5a65c1 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,5 +1,6 @@ -import { NextAuthOptions } from 'next-auth'; +import { NextAuthOptions, User } from 'next-auth'; import CredentialsProvider from 'next-auth/providers/credentials'; +import { JWT } from 'next-auth/jwt'; export const authOptions: NextAuthOptions = { providers: [ @@ -15,18 +16,54 @@ export const authOptions: NextAuthOptions = { } // TODO: Implement actual authentication logic + // For now, generate a unique ID based on email + const userId = Buffer.from(credentials.email).toString('base64'); + return { - id: '1', + id: userId, email: credentials.email, name: credentials.email.split('@')[0], - }; + first_name: credentials.email.split('@')[0], + last_name: '', + username: credentials.email, + role: ['user'] + } satisfies User; } }) ], session: { strategy: 'jwt', + maxAge: 30 * 24 * 60 * 60, // 30 days }, + jwt: { + maxAge: 30 * 24 * 60 * 60, // 30 days + }, + secret: process.env.NEXTAUTH_SECRET, pages: { - signIn: '/login', + signIn: '/courrier/login', }, + callbacks: { + async jwt({ token, user }) { + if (user) { + token.id = user.id; + token.email = user.email; + token.first_name = user.first_name; + token.last_name = user.last_name; + token.username = user.username; + token.role = user.role; + } + return token; + }, + async session({ session, token }) { + if (token) { + session.user.id = token.id as string; + session.user.email = token.email as string; + session.user.first_name = token.first_name as string; + session.user.last_name = token.last_name as string; + session.user.username = token.username as string; + session.user.role = token.role as string[]; + } + return session; + } + } }; \ No newline at end of file