Skip to content

Commit

Permalink
define next-auth config options
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMwendwa committed Nov 28, 2023
1 parent 2f2b630 commit ac564a2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions auth.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { NextAuthConfig } from 'next-auth';

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

0 comments on commit ac564a2

Please sign in to comment.