feat: support guest session (#919)
This commit is contained in:
parent
24cb2ce19b
commit
9279135355
34 changed files with 741 additions and 288 deletions
|
|
@ -9,31 +9,5 @@ export const authConfig = {
|
|||
// added later in auth.ts since it requires bcrypt which is only compatible with Node.js
|
||||
// while this file is also used in non-Node.js environments
|
||||
],
|
||||
callbacks: {
|
||||
authorized({ auth, request: { nextUrl } }) {
|
||||
const isLoggedIn = !!auth?.user;
|
||||
const isOnChat = nextUrl.pathname.startsWith('/');
|
||||
const isOnRegister = nextUrl.pathname.startsWith('/register');
|
||||
const isOnLogin = nextUrl.pathname.startsWith('/login');
|
||||
|
||||
if (isLoggedIn && (isOnLogin || isOnRegister)) {
|
||||
return Response.redirect(new URL('/', nextUrl as unknown as URL));
|
||||
}
|
||||
|
||||
if (isOnRegister || isOnLogin) {
|
||||
return true; // Always allow access to register and login pages
|
||||
}
|
||||
|
||||
if (isOnChat) {
|
||||
if (isLoggedIn) return true;
|
||||
return false; // Redirect unauthenticated users to login page
|
||||
}
|
||||
|
||||
if (isLoggedIn) {
|
||||
return Response.redirect(new URL('/', nextUrl as unknown as URL));
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
},
|
||||
callbacks: {},
|
||||
} satisfies NextAuthConfig;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue