Skip to content

Commit

Permalink
fix(middleware): use relative URL for sign-in page callbackUrl (#4534)
Browse files Browse the repository at this point in the history
* Use relative URL for middleware's signin callbackUrl

* Include params to callbackUrl if any

* For testing purpose, append params to existing link for test instead of create another one

* Update apps/dev/components/header.js

Co-authored-by: CODY Mai <nhan.mai@shiftasia.com>
Co-authored-by: Thang Vu <31528554+ThangHuuVu@users.noreply.github.com>
  • Loading branch information
3 people committed May 31, 2022
1 parent 5b8a619 commit 75602a3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next-auth/src/next/middleware.ts
Expand Up @@ -101,7 +101,7 @@ async function handleMiddleware(

// the user is not logged in, redirect to the sign-in page
const signInUrl = new URL(signInPage, req.nextUrl.origin)
signInUrl.searchParams.append("callbackUrl", req.url)
signInUrl.searchParams.append("callbackUrl", `${req.nextUrl.pathname}${req.nextUrl.search}`)
return NextResponse.redirect(signInUrl)
}

Expand Down

1 comment on commit 75602a3

@thevuong
Copy link

@thevuong thevuong commented on 75602a3 Jun 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes conflicts with the assertConfig method when testing with the isValidHttpUrl method.
This problem occurs when used with middleware in Next.js: default-re-export

Please sign in to comment.