- Install next-auth@beta, bcryptjs, zod, and @auth/prisma-adapter - Create auth.ts with credentials provider and JWT session strategy - Create auth.config.ts for edge-compatible middleware configuration - Add NextAuth type extensions for session and JWT - Create API route handler for authentication - Configure environment variables for NextAuth - Add AUTH_SETUP.md documentation Task: 1. Set up authentication infrastructure Requirements: 1.1, 2.1
29 lines
685 B
TypeScript
29 lines
685 B
TypeScript
import type { NextAuthConfig } from "next-auth"
|
|
|
|
export const authConfig = {
|
|
pages: {
|
|
signIn: "/auth/login",
|
|
signOut: "/auth/logout",
|
|
error: "/auth/error",
|
|
},
|
|
callbacks: {
|
|
authorized({ auth, request: { nextUrl } }) {
|
|
const isLoggedIn = !!auth?.user
|
|
const isOnAuthPage = nextUrl.pathname.startsWith("/auth")
|
|
|
|
// Allow access to auth pages when not logged in
|
|
if (isOnAuthPage) {
|
|
return true
|
|
}
|
|
|
|
// Redirect to login if not authenticated
|
|
if (!isLoggedIn) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
},
|
|
},
|
|
providers: [], // Providers will be added in auth.ts
|
|
} satisfies NextAuthConfig
|