OIDC/SSO flow drops invite code context (multi-community auto-join issue)

(#4737) Bug Open: Awaiting confirmation desktop self-hosting

Thread

Comment by errno0x0d
errno0x0d OP1 vote
After inspecting the codebase, the fix is even simpler than expected because the client and OAuth state handling are already doing their job!
  1. AuthLoginLayout.tsx already passes redirect_to: ssoRedirectPath (e.g. /invite/<code_b>) to POST /v1/auth/sso/start.
  2. startSso preserves it in statePayload.redirectTo.
  3. completeLogin in SsoService.ts already retrieves const redirectTo = statePayload.redirectTo ?? ''.
The only missing link is that resolveUserFromClaims does not receive redirectTo, so it only falls back to config.instance.autoJoinInviteCode.

Suggested fix in SsoService.ts & SsoUtils.ts:

  1. In SsoUtils.ts:
    export function extractInviteCodeFromRedirect(redirectTo?: string): string | null {
      const sanitized = sanitizeSsoRedirectTo(redirectTo);
      if (!sanitized) return null;
      const match = sanitized.match(/^\/invite\/([a-zA-Z0-9_-]+)(?:[?#]|$)/);
      return match ? match[1] : null;
    }
  1. In SsoService.ts:
Pass redirectTo into resolveUserFromClaims(..., redirectTo) and resolve the effective invite code matching the GuildEntry.ts pattern (inviteCode || autoJoinInviteCode):
const inviteCodeFromRedirect = extractInviteCodeFromRedirect(redirectTo);
const autoJoinInviteCode =
  inviteCodeFromRedirect || this.apiContext.services.config.instance.autoJoinInviteCode?.trim() || null;
This guarantees that:
  • Visitors arriving via a specific /invite/<code_b> link auto-join that specific guild upon SSO completion.
  • Generic visitors without an invite link still fall back to FLUXER_AUTO_JOIN_INVITE_CODE.