MCPcopy Create free account
hub / github.com/devmdfaiz/cloud-clove / authMiddleware

Function authMiddleware

src/middleware.ts:17–43  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

15}
16
17export default async function authMiddleware(req: NextRequest) {
18 const session = await getMiddlewareSession(req);
19 const pathname = req.nextUrl.pathname
20 const url = req.url
21
22 if(pathname === "/"){
23 return NextResponse.redirect(new URL("/dashboard", url))
24 }
25
26 if(pathname.startsWith("/dashboard")){
27 if(session){
28 return NextResponse.next()
29 }
30
31 return NextResponse.redirect(new URL("/sign-in", url))
32 }
33
34 if(pathname.startsWith("/sign-")){
35 if(!session){
36 return NextResponse.next()
37 }
38
39 return NextResponse.redirect(new URL("/dashboard", url))
40 }
41
42 return NextResponse.next();
43}
44
45export const config = {
46 matcher: [

Callers

nothing calls this directly

Calls 1

getMiddlewareSessionFunction · 0.85

Tested by

no test coverage detected