fix: fetch full user profile after login in auth callback and welcome page to ensure correct display name

This commit is contained in:
Usman Baig
2026-02-08 21:36:42 +01:00
parent ff456ef4d6
commit 3e8edd188a
2 changed files with 33 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ import { createCheckoutSession } from '@/lib/api/billing'
import { createSite, type Site } from '@/lib/api/sites'
import { setSessionAction } from '@/app/actions/auth'
import { useAuth } from '@/lib/auth/context'
import apiRequest from '@/lib/api/client'
import { getAuthErrorMessage } from '@/lib/utils/authErrors'
import {
trackWelcomeStepView,
@@ -147,13 +148,19 @@ function WelcomeContent() {
const { access_token } = await switchContext(org.organization_id)
const result = await setSessionAction(access_token)
if (result.success && result.user) {
login(result.user)
try {
const fullProfile = await apiRequest<{ id: string; email: string; display_name?: string; totp_enabled: boolean; org_id?: string; role?: string }>('/auth/user/me')
const merged = { ...fullProfile, org_id: result.user.org_id ?? fullProfile.org_id, role: result.user.role ?? fullProfile.role }
login(merged)
} catch {
login(result.user)
}
router.refresh()
trackWelcomeWorkspaceSelected()
setStep(3)
}
} catch (err) {
toast.error(getAuthErrorMessage(err) || 'Failed to switch workspace')
toast.error(getAuthErrorMessage(err) || 'Failed to switch organization')
} finally {
setSwitchingOrgId(null)
}
@@ -178,7 +185,13 @@ function WelcomeContent() {
const { access_token } = await switchContext(org.id)
const result = await setSessionAction(access_token)
if (result.success && result.user) {
login(result.user)
try {
const fullProfile = await apiRequest<{ id: string; email: string; display_name?: string; totp_enabled: boolean; org_id?: string; role?: string }>('/auth/user/me')
const merged = { ...fullProfile, org_id: result.user.org_id ?? fullProfile.org_id, role: result.user.role ?? fullProfile.role }
login(merged)
} catch {
login(result.user)
}
router.refresh()
}
trackWelcomeWorkspaceCreated(!!(typeof window !== 'undefined' && localStorage.getItem('pulse_pending_checkout')))