courrier multi account restore compose
This commit is contained in:
parent
95ea63db2f
commit
0fbc339447
45
lib/auth.ts
45
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 CredentialsProvider from 'next-auth/providers/credentials';
|
||||||
|
import { JWT } from 'next-auth/jwt';
|
||||||
|
|
||||||
export const authOptions: NextAuthOptions = {
|
export const authOptions: NextAuthOptions = {
|
||||||
providers: [
|
providers: [
|
||||||
@ -15,18 +16,54 @@ export const authOptions: NextAuthOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement actual authentication logic
|
// TODO: Implement actual authentication logic
|
||||||
|
// For now, generate a unique ID based on email
|
||||||
|
const userId = Buffer.from(credentials.email).toString('base64');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: '1',
|
id: userId,
|
||||||
email: credentials.email,
|
email: credentials.email,
|
||||||
name: credentials.email.split('@')[0],
|
name: credentials.email.split('@')[0],
|
||||||
};
|
first_name: credentials.email.split('@')[0],
|
||||||
|
last_name: '',
|
||||||
|
username: credentials.email,
|
||||||
|
role: ['user']
|
||||||
|
} satisfies User;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
session: {
|
session: {
|
||||||
strategy: 'jwt',
|
strategy: 'jwt',
|
||||||
|
maxAge: 30 * 24 * 60 * 60, // 30 days
|
||||||
},
|
},
|
||||||
|
jwt: {
|
||||||
|
maxAge: 30 * 24 * 60 * 60, // 30 days
|
||||||
|
},
|
||||||
|
secret: process.env.NEXTAUTH_SECRET,
|
||||||
pages: {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user