mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-26 22:26:10 +00:00
* Update to latest + refactoring. * idk, fuck it * Trying to make it work * add `next-auth` fixes (#211) Co-authored-by: Balázs Orbán <info@balazsorban.com> * Another one * test * bump `next` and `next-auth`, `bcrypt` -> `bcryptjs` * simplify * upgrade types * add basic html form validatoin * add zod validation * update * remove non next-auth changes * revert * revert * revert * revert * uses bcrypt * fix imports * tweaks * revert * revert * revert --------- Co-authored-by: Lee Robinson <lrobinson2011@gmail.com> Co-authored-by: Delba de Oliveira <delbabrown@gmail.com>
25 lines
758 B
TypeScript
25 lines
758 B
TypeScript
import type { NextAuthConfig } from 'next-auth';
|
|
|
|
export const authConfig = {
|
|
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 Response.redirect(new URL('/login', nextUrl));
|
|
return true;
|
|
} else if (isLoggedIn) {
|
|
return Response.redirect(new URL('/dashboard', nextUrl));
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
pages: {
|
|
signIn: '/login',
|
|
},
|
|
} satisfies NextAuthConfig;
|