Skip to content

Commit af2460b

Browse files
committed
fix: correct error redirect URL
1 parent c14ee46 commit af2460b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

middleware.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function customDomainMiddleware (request, domain, subName) {
4343
// A: the user is trying to login or signup, redirect to the Auth Sync API
4444
if (pathname.startsWith('/login') || pathname.startsWith('/signup')) {
4545
const signup = pathname.startsWith('/signup')
46-
return redirectToAuthSync(searchParams, domain, csrfToken, signup, headers)
46+
return redirectToAuthSync(request, searchParams, domain, csrfToken, signup, headers)
4747
}
4848
// B: if we have a verification token, exchange it for a session token
4949
if (searchParams.has('synctoken')) return establishAuthSync(request, searchParams, csrfToken, headers)
@@ -79,9 +79,9 @@ async function customDomainMiddleware (request, domain, subName) {
7979
}
8080

8181
// redirect to the Auth Sync API
82-
async function redirectToAuthSync (searchParams, domain, csrfToken, signup, headers) {
82+
async function redirectToAuthSync (request, searchParams, domain, csrfToken, signup, headers) {
8383
// bail if we don't have a csrfToken
84-
if (!csrfToken) return NextResponse.redirect('/error', { headers })
84+
if (!csrfToken) return NextResponse.redirect(new URL('/error', request.url), { headers })
8585

8686
const syncUrl = new URL('/api/auth/sync', SN_MAIN_DOMAIN)
8787
syncUrl.searchParams.set('domain', domain)
@@ -109,7 +109,7 @@ async function redirectToAuthSync (searchParams, domain, csrfToken, signup, head
109109
// Exchange verification token for JWT session cookie via POST to /api/auth/sync
110110
async function establishAuthSync (request, searchParams, csrfToken, headers) {
111111
// bail if we don't have a csrfToken
112-
if (!csrfToken) return NextResponse.redirect('/error', { headers })
112+
if (!csrfToken) return NextResponse.redirect(new URL('/error', request.url), { headers })
113113
// get the verification token from the search params
114114
const token = searchParams.get('synctoken')
115115
// get the redirectUri from the search params

0 commit comments

Comments
 (0)