added user rig submission, logout | initial
This commit is contained in:
parent
9261fbc165
commit
b341a3675e
8 changed files with 635 additions and 420 deletions
24
middleware.ts
Normal file
24
middleware.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
const PROTECTED_PATHS = ["/my", "/api/my"];
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
const { pathname } = req.nextUrl;
|
||||
const needsAuth = PROTECTED_PATHS.some(
|
||||
(p) => pathname === p || pathname.startsWith(p + "/")
|
||||
);
|
||||
if (!needsAuth) return NextResponse.next();
|
||||
|
||||
const hasToken = Boolean(req.cookies.get("ma_at")?.value);
|
||||
if (!hasToken) {
|
||||
const url = new URL("/sign-in", req.url);
|
||||
url.searchParams.set("next", pathname);
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!_next|static|favicon.ico).*)"],
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue