Skip to content

Commit b4eeb80

Browse files
JivusAyrusmaxbol
authored andcommitted
feat: enhance redirect logic in auth controller to include onboarding parameter (wundergraph#2476)
1 parent 6e64810 commit b4eeb80

File tree

1 file changed

+17
-7
lines changed
  • controlplane/src/core/controllers

1 file changed

+17
-7
lines changed

controlplane/src/core/controllers/auth.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,26 @@ const plugin: FastifyPluginCallback<AuthControllerOptions> = function Auth(fasti
400400
// Set the sso cookie.
401401
opts.authUtils.createSsoCookie(res, ssoSlug);
402402
}
403+
// Determine the target URL
404+
let targetUrl = opts.webBaseUrl;
403405
if (redirectURL) {
404-
if (redirectURL.startsWith(opts.webBaseUrl)) {
405-
res.redirect(redirectURL);
406-
} else {
407-
res.redirect(opts.webBaseUrl);
406+
try {
407+
const redirectOrigin = new URL(redirectURL).origin;
408+
const webBaseOrigin = new URL(opts.webBaseUrl).origin;
409+
if (redirectOrigin === webBaseOrigin) {
410+
targetUrl = redirectURL;
411+
}
412+
} catch {
413+
// On parse error, keep targetUrl as opts.webBaseUrl
408414
}
409-
} else if (orgs === 0) {
410-
res.redirect(opts.webBaseUrl + '?migrate=true');
415+
}
416+
417+
// Append onboarding parameter if the user has no orgs
418+
if (orgs === 0) {
419+
const separator = targetUrl.includes('?') ? '&' : '?';
420+
res.redirect(targetUrl + separator + 'onboarding=true');
411421
} else {
412-
res.redirect(opts.webBaseUrl);
422+
res.redirect(targetUrl);
413423
}
414424
} catch (err: any) {
415425
if (err instanceof AuthenticationError) {

0 commit comments

Comments
 (0)