import type { NextAuthConfig } from "next-auth" export const authConfig = { trustHost: true, pages: { signIn: "/login", }, callbacks: { authorized({ auth, request: { nextUrl } }) { const isLoggedIn = !!auth?.user const isDashboard = nextUrl.pathname.startsWith("/create") || nextUrl.pathname.startsWith("/history") || nextUrl.pathname.startsWith("/profile") const isAuthPage = nextUrl.pathname.startsWith("/login") || nextUrl.pathname.startsWith("/signup") if (isDashboard) { if (isLoggedIn) return true return false // Redirect unauthenticated users to login page } else if (isAuthPage && isLoggedIn) { return Response.redirect(new URL("/create", nextUrl)) } return true }, async jwt({ token, user }) { if (user) { token.id = user.id } return token }, async session({ session, token }) { if (token && session.user) { session.user.id = token.id as string } return session }, }, providers: [], // Configured in auth.ts } satisfies NextAuthConfig