-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
29 lines (26 loc) · 855 Bytes
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { withAuth, NextAuthMiddlewareOptions } from 'next-auth/middleware'
import * as jose from 'jose'
import { JWT } from 'next-auth/jwt'
import { decode } from '.../utils/jwt'
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
// export default withAuth({
// callbacks: {
// authorized({ req, token }) {
// // `/admin` requires admin role
// if (req.nextUrl.pathname === "/admin") {
// return token?.userRole === "admin"
// }
// // `/me` only requires the user to be logged in
// return !!token
// },
// },
// })
export default withAuth({
jwt: { decode },
callbacks: {
async authorized({ token, req }) {
return !!token
},
},
} as NextAuthMiddlewareOptions)
export const config = { matcher: ['/try/auth/admin', '/try/auth/me'] }