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?
What is the exact flow that you are looking to accomplish with your implementation? Basically, do you wish to invite members to your organizations and have them either be redirected to the dashboard or to the signup page respectively?
The usual flow for such an implementation would be to send organizations invites via the Management API where you state the recipient, organization, application and database connection that you wish to use.
If an unauthenticated user accesses the application, they will be redirected to the login page, unfortunately, you will not be able to redirect them to the signup page directly unless you are passing in the parameter screen_hint=signup in the /authorize call. Also, if you wish to have an authenticated user redirected to the dashboard when the invitation link is being accessed, you would need to set the Application Login URI to be that specific URL.
If you have any other questions or anything else I can help you with, let me know!