second alternative

This commit is contained in:
Balázs Orbán
2023-10-14 00:28:44 +02:00
parent e20b9efd81
commit ff22cbc024
3 changed files with 17 additions and 9 deletions

View File

@@ -0,0 +1,11 @@
import type { NextAuthConfig } from 'next-auth';
export default {
providers: [],
callbacks: {
authorized({ auth, request: { nextUrl } }) {
return !nextUrl.pathname.startsWith('/dashboard') || !!auth?.user;
},
},
pages: { signIn: '/login' },
} satisfies NextAuthConfig;

View File

@@ -3,6 +3,7 @@ import Credentials from 'next-auth/providers/credentials';
import bcrypt from 'bcrypt';
import { sql } from '@vercel/postgres';
import type { User } from '@/app/lib/definitions';
import authConfig from './auth.config';
async function getUser(email: string) {
try {
@@ -20,7 +21,9 @@ export const {
signIn,
signOut,
} = NextAuth({
...authConfig,
providers: [
...authConfig.providers,
Credentials({
name: 'Sign-In with Credentials',
credentials: {
@@ -48,12 +51,4 @@ export const {
},
}),
],
callbacks: {
authorized({ auth, request: { nextUrl } }) {
return !nextUrl.pathname.startsWith('/dashboard') || !!auth?.user;
},
},
pages: {
signIn: '/login',
},
});

View File

@@ -1 +1,3 @@
export { auth as middleware } from './auth';
import authConfig from './auth.config';
import NextAuth from 'next-auth';
export default NextAuth(authConfig).auth;