Skip to content

Commit

Permalink
fix: redirect to callback when the user is logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul Ranete committed Jan 29, 2025
1 parent 4b9fe09 commit 6cca08f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/wallet/frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const isPublicPath = (path: string) => {
const publicPaths = ['/auth*']

export async function middleware(req: NextRequest) {
const callbackUrl = req.nextUrl.searchParams.get('callbackUrl')
const isPublic = isPublicPath(req.nextUrl.pathname)
const cookieName = process.env.COOKIE_NAME || 'testnet.cookie'

Expand Down Expand Up @@ -39,7 +40,7 @@ export async function middleware(req: NextRequest) {
}

if (isPublic) {
return NextResponse.redirect(new URL('/', req.url))
return NextResponse.redirect(new URL(callbackUrl ?? '/', req.url))
}
} else {
// If the user is not logged in and tries to access a private resource,
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/frontend/src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const LoginPage: NextPageWithLayout = () => {
setCallbackPath(urlFromStorage ?? '/');
} else {
sessionStorage.setItem(SessionStorageKeys.CallbackUrl, callbackUrl)
setCallbackPath(callbackUrl)
}

}, [callbackUrl])
Expand Down

0 comments on commit 6cca08f

Please sign in to comment.