-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
48 lines (40 loc) · 1.44 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// v5 one line:
export { auth as middleware } from 'auth';
// from official next.js page:
// import NextAuth from 'next-auth';
// import { authConfig } from './auth.config';
// export default NextAuth(authConfig).auth;
// export const config = {
// // https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
// matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
// };
//////
// old below
////
// // with out a defined matcher; this one line applies next-auth to the entire project:
// // export { default } from 'next-auth/middleware';
// // https://next-auth.js.org/configuration/nextjs#advanced-usage
// // v4
// import { withAuth, NextRequestWithAuth } from 'next-auth/middleware';
// // import {type }
// export default withAuth(
// // withAuth augments our 'Request' with the user's token;
// function middleware(request: NextRequestWithAuth) {
// console.log(request.nextUrl.pathname);
// console.log(request.nextauth.token);
// },
// {
// callbacks: {
// authorized: ({ token }) => token?.role === 'admin',
// },
// },
// );
// // callbacks: {
// // authorized: async ({ req, token }) => {
// // if (req.nextUrl.pathname.startsWith("/admin")) return token?.role === "admin";
// // return !!token;
// // },
// // },
// // });
// // export const config = { matcher: ['/admin:path*', '/profile'] };
// export const config = { matcher: ['/extra', '/dashboard'] };