mirror of
https://github.com/BradNut/nextjs-dashboard
synced 2025-09-08 17:40:30 +00:00
26 lines
731 B
TypeScript
26 lines
731 B
TypeScript
import type { NextAuthConfig } from "next-auth";
|
|
|
|
export const authConfig = {
|
|
pages: {
|
|
signIn: "/login",
|
|
},
|
|
providers: [
|
|
// 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 isOnDashboard = nextUrl.pathname.startsWith("/dashboard");
|
|
if (isOnDashboard) {
|
|
if (isLoggedIn) {
|
|
return true;
|
|
}
|
|
return false; // Redirect unathenticated users to login page
|
|
} else if (isLoggedIn) {
|
|
return Response.redirect(new URL("/dashboard", nextUrl));
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
} satisfies NextAuthConfig;
|