-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL Redirection Error on Authentication Failure (Middleware file) #10824
Comments
This issue is found after upgrading Next.js to 14.2. The current solution is to downgrade Next.js for now |
@sfsajid91 so, let this issue be opened? |
Let the issue be opened till the fix |
I tried to do this, but got stuck in infinite redirection: import { auth } from '@/auth'
export default auth((req) => {
if (!req.auth) {
const url = new URL('/auth/sign-in', req.nextUrl.origin)
return Response.redirect(url)
}
})
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
} "next": "14.2.3", |
@oyal to avoid infinite redirection, you'll need to exclude /login from the middleware export const config = {
matcher: ['/((?!/auth/sign-in|api|_next/static|_next/image|favicon.ico).*)'],
} |
@mdfaizanahmed786 seems like a documentation issue to me. The example code is wrong // input: 'http://localhost:3000/', output: 'http:/auth/signin/localhost:3000/'
const url = req.url.replace(req.nextUrl.pathname, "/auth/signin") It should use the syntax |
Closing as duplicated, as it was fixed in #10815 |
Describe the issue
Page URL: https://authjs.dev/getting-started/session-management/protecting#nextjs-middleware
This redirects to the incorrect URL path if no session: http://login/localhost:3000/
Approach to Fix
Can use a similar standard approach
Expected behavior
It should redirect to http://localhost:3000/login
The text was updated successfully, but these errors were encountered: