fix: handle access_token only response from switchContext

This commit is contained in:
Usman Baig
2026-01-22 01:36:56 +01:00
parent 806b149bc7
commit cbb2255024
5 changed files with 23 additions and 17 deletions

View File

@@ -37,9 +37,9 @@ export async function createOrganization(name: string, slug: string): Promise<Or
}
// * Switch context to organization (returns new token)
export async function switchContext(organizationId: string): Promise<{ token: string, refresh_token: string }> {
export async function switchContext(organizationId: string): Promise<{ access_token: string }> {
// * Route in main.go is /api/v1/auth/switch-context
return apiRequest<{ token: string, refresh_token: string }>('/auth/switch-context', {
return apiRequest<{ access_token: string }>('/auth/switch-context', {
method: 'POST',
body: JSON.stringify({ organization_id: organizationId }),
})

View File

@@ -123,10 +123,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
console.log('Auto-switching to organization:', firstOrg.organization_name)
try {
const { token, refresh_token } = await switchContext(firstOrg.organization_id)
const { access_token } = await switchContext(firstOrg.organization_id)
// * Update session cookie
const result = await setSessionAction(token, refresh_token)
const result = await setSessionAction(access_token)
if (result.success && result.user) {
setUser(result.user)
localStorage.setItem('user', JSON.stringify(result.user))