mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-11 09:51:47 +00:00
second alternative
This commit is contained in:
11
dashboard/15-final/auth.config.ts
Normal file
11
dashboard/15-final/auth.config.ts
Normal 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;
|
||||
@@ -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',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
export { auth as middleware } from './auth';
|
||||
import authConfig from './auth.config';
|
||||
import NextAuth from 'next-auth';
|
||||
export default NextAuth(authConfig).auth;
|
||||
|
||||
Reference in New Issue
Block a user