How could we implement next-auth with the new next.js middleware? #3041
Answered
by
balazsorban44
callumok2004
asked this question in
Help
-
import type { NextFetchEvent } from 'next/server'
import { getSession } from "next-auth/client";
import { NextResponse } from "next/server";
export async function middleware(request: any, event: NextFetchEvent) {
const path = request.nextUrl.href,
notAllowed = ["/dashboard", "/admin"],
session = await getSession();
let error: string | boolean = false;
if(!session && notAllowed.some(x => path.startsWith(x))) error = "Redirecting to login...";
console.log(1, session)
if(error) return NextResponse.rewrite(`/auth/${error}`);
} Using the above code, the session always returns null, even if there is an active session, Is there any workaround to this? |
Beta Was this translation helpful? Give feedback.
Answered by
balazsorban44
Oct 27, 2021
Replies: 1 comment
-
This will require some work on our side to do correctly, but I will have a look. #3037
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
balazsorban44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will require some work on our side to do correctly, but I will have a look. #3037
getSession
won't work, it is slow... #1535