You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
783 B
TypeScript

import type { NextAuthConfig } from 'next-auth';
export const authConfig = {
pages: {
signIn: '/login',
},
callbacks: {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnLogin = nextUrl.pathname.startsWith('/login');
const isPublicPath = nextUrl.pathname === '/' || nextUrl.pathname.startsWith('/api') || isOnLogin;
if (isOnLogin) {
if (isLoggedIn) return Response.redirect(new URL('/dashboard', nextUrl));
return true;
}
if (!isLoggedIn && !isPublicPath) {
return false; // Redirect unauthenticated users to login page
}
return true;
},
},
providers: [], // Add providers with an empty array for now
} satisfies NextAuthConfig;