Spaces:
Sleeping
Sleeping
Download middleware.ts from underrate/webdev-service: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/underrate/webdev-service/resolve/main/middleware.ts
- Command line
-
hf download hf://spaces/underrate/webdev-service/middleware.ts
-
curl -L -o middleware.ts https://huggingface.co/spaces/underrate/webdev-service/resolve/main/middleware.ts
1.13 kB
| import { auth } from "@/lib/auth" | |
| import { NextResponse } from "next/server" | |
| import type { NextRequest } from "next/server" | |
| export async function middleware(request: NextRequest) { | |
| const session = await auth() | |
| const isAuth = !!session?.user | |
| const isAuthPage = | |
| request.nextUrl.pathname.startsWith("/admin/login") || | |
| request.nextUrl.pathname.startsWith("/admin/forgot-password") || | |
| request.nextUrl.pathname.startsWith("/admin/reset-password") | |
| const isAdminPage = request.nextUrl.pathname.startsWith("/admin") | |
| if (isAuthPage) { | |
| if (isAuth) { | |
| return NextResponse.redirect(new URL("/admin/dashboard", request.url)) | |
| } | |
| return null | |
| } | |
| if (isAdminPage && !isAuth) { | |
| let from = request.nextUrl.pathname | |
| if (request.nextUrl.search) { | |
| from += request.nextUrl.search | |
| } | |
| return NextResponse.redirect( | |
| new URL(`/admin/login?from=${encodeURIComponent(from)}`, request.url) | |
| ) | |
| } | |
| return null | |
| } | |
| export const config = { | |
| matcher: ["/admin/:path*"], | |
| } | |