implemented login

This commit is contained in:
2024-01-06 10:50:27 +01:00
parent 60a89b88ac
commit 52d4c35c2e
14 changed files with 257 additions and 35 deletions

24
auth.config.ts Normal file
View File

@@ -0,0 +1,24 @@
/**
* @module auth.config.ts
* @description defines how user session is to be checked and redirects anonymous user to login page
*/
import type { NextAuthConfig } from 'next-auth';
export const authConfig = {
pages: {
signIn: '/login',
},
// this will prevent users from accessing the dashboard pages unless they are logged in
callbacks: {
// The authorized callback is used to verify if the request is authorized to access a
// page via Next.js Middleware. It is called before a request is completed, and it
// receives an object with the auth and request properties.
// The auth property contains the user's session, and the request property contains
// the incoming request.
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
return(isLoggedIn);
},
},
providers: [], // Add providers with an empty array for now
} satisfies NextAuthConfig;