Spaces:
Paused
Paused
Download src/auth.config.ts from veltrixcode/retest: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/veltrixcode/retest/resolve/main/src/auth.config.ts
- Command line
-
hf download hf://spaces/veltrixcode/retest/src/auth.config.ts
-
curl -L -o auth.config.ts https://huggingface.co/spaces/veltrixcode/retest/resolve/main/src/auth.config.ts
1.31 kB
| 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 | |