• 1 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.
  • 1 vote
    Implementation suggestion to easily fix this:
    1. In the client apps (Web, Desktop, Mobile): When an unauthenticated visitor clicks "Login with SSO" on an /invite/:code landing screen, ensure POST /v1/auth/sso/start includes redirect_to: window.location.pathname (or an explicit invite_code parameter) so it gets preserved in the OAuth statePayload.
    1. In SsoService (completeLogin / resolveUserFromClaims): Extract the invite code from statePayload.redirectTo if it matches /invite/:code and prioritize it:
    const inviteMatch = statePayload.redirectTo?.match(/\/invite\/([a-zA-Z0-9_-]+)/);
    const inviteCodeToJoin = inviteMatch ? inviteMatch[1] : autoJoinInviteCode;
    
    if (inviteCodeToJoin) {
      await maybeAutoJoinInvite(this.inviteService, {
        userId: user.id,
        inviteCode: inviteCodeToJoin,
        requestCache
      });
    }
    
    This ensures the user seamlessly lands inside the specific invited guild across all platforms, while preserving the static FLUXER_AUTO_JOIN_INVITE_CODE fallback for generic root signups.