I’m working on a Next.js app and trying to implement an invitation flow. When an invitation link is accessed (e.g., with ?invitation=xyz&organization=abc
), I want to redirect users to either the dashboard (if they’re logged in) or to the signup/login page with the invitation parameters preserved.
if (invitation && organization) {
if (user) {
router.push(`/dashboard?invitation=${invitation}&organization=${organization}${organization_name ? `&organization_name=${organization_name}` : ''}`);
} else {
const authUrl = new URL('/authorize', window.location.origin);
authUrl.searchParams.set('invitation', invitation);
authUrl.searchParams.set('organization', organization);
if (organization_name) {
authUrl.searchParams.set('organization_name', organization_name);
}
window.location.href = authUrl.toString();
}
}
The issue I’m facing is that users are not being redirected to the signup page (/authorize
) as expected when not logged in. Instead, the redirect either fails silently or redirects to login screen.
Has anyone implemented something similar in Next.js and can help me figure out what I might be missing? Could this be related to Next.js routing, Auth0 configuration, or browser behavior?
Thanks,
Sridhar