-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.config.ts
33 lines (31 loc) · 897 Bytes
/
auth.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { NextAuthConfig, Session } from "next-auth";
export const authConfig = {
secret: process.env.AUTH_SECRET,
callbacks: {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnLogin = nextUrl.pathname == "/";
// cant access dashboard if not authorized
return isLoggedIn && isOnLogin
? Response.redirect(new URL("/chat", nextUrl))
: !!auth;
},
jwt({ token, profile }) {
if (profile) {
token.id = profile.id;
token.image = profile.avatar_url || profile.picture;
}
return token;
},
session: ({ session, token }: { session: Session; token?: any }) => {
if (session?.user && token?.id) {
session.user.id = String(token.id);
}
return session;
},
},
providers: [],
pages: {
signIn: "/",
},
} satisfies NextAuthConfig;