-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5167c4a
commit d4f9d82
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
|
||
export default function page() { | ||
return ( | ||
<div>Admin Page</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
export { default } from "next-auth/middleware"; | ||
import { getToken } from "next-auth/jwt"; | ||
|
||
// This function can be marked `async` if using `await` inside | ||
export async function middleware(request: NextRequest) { | ||
const token = await getToken({ req: request }); | ||
const url = request.nextUrl; | ||
|
||
if (url.pathname === "/admin") { | ||
if (token?.role!=="ADMIN") { | ||
return NextResponse.redirect(new URL("/", request.url)); | ||
} | ||
} | ||
} | ||
|
||
// See "Matching Paths" below to learn more | ||
export const config = { | ||
matcher: ["/:path*", "/"], | ||
}; |