| 57 | }; |
| 58 | |
| 59 | const withAuth = async (req: NextRequestWithAuth) => { |
| 60 | if (process.env.LOCAL_CMS_PROVIDER) return; |
| 61 | |
| 62 | const token = await getToken({ req }); |
| 63 | |
| 64 | if (!token) { |
| 65 | return NextResponse.redirect(new URL('/invalidsession', req.url)); |
| 66 | } |
| 67 | |
| 68 | const user = await fetch( |
| 69 | `${process.env.NEXT_PUBLIC_BASE_URL_LOCAL}/api/user?token=${token.jwtToken}`, |
| 70 | ); |
| 71 | |
| 72 | const json = await user.json(); |
| 73 | if (!json.user) { |
| 74 | return NextResponse.redirect(new URL('/invalidsession', req.url)); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | export async function middleware(req: NextRequestWithAuth) { |
| 79 | const { pathname } = req.nextUrl; |