2024-08-12 14:21:08 +00:00
|
|
|
import type { NextAuthConfig } from 'next-auth';
|
2024-09-10 10:29:26 +00:00
|
|
|
import Credentials from 'next-auth/providers/credentials';
|
2024-08-12 14:21:08 +00:00
|
|
|
|
|
|
|
export const authConfig = {
|
|
|
|
pages: {
|
|
|
|
signIn: '/login',
|
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
authorized({ auth, request: { nextUrl } }) {
|
|
|
|
const isLoggedIn = !!auth?.user;
|
2024-09-10 10:29:26 +00:00
|
|
|
console.log(`isLoggedIn: ${isLoggedIn}`)
|
|
|
|
const isOnDashboard = nextUrl.pathname.startsWith('/');
|
2024-08-12 14:21:08 +00:00
|
|
|
if (isOnDashboard) {
|
|
|
|
if (isLoggedIn) return true;
|
|
|
|
return false; // Redirect unauthenticated users to login page
|
|
|
|
} else if (isLoggedIn) {
|
2024-09-10 10:29:26 +00:00
|
|
|
return Response.redirect(new URL('/', nextUrl));
|
2024-08-12 14:21:08 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
2024-09-10 10:29:26 +00:00
|
|
|
providers: [Credentials({})], // Add providers with an empty array for now
|
2024-08-12 14:21:08 +00:00
|
|
|
} satisfies NextAuthConfig;
|