fix: handle access_token only response from switchContext
This commit is contained in:
@@ -97,9 +97,11 @@ export async function exchangeAuthCode(code: string, codeVerifier: string, redir
|
||||
}
|
||||
}
|
||||
|
||||
export async function setSessionAction(accessToken: string, refreshToken: string) {
|
||||
export async function setSessionAction(accessToken: string, refreshToken?: string) {
|
||||
try {
|
||||
console.log('[setSessionAction] Decoding token...')
|
||||
if (!accessToken) throw new Error('Access token is missing')
|
||||
|
||||
const payloadPart = accessToken.split('.')[1]
|
||||
const payload: UserPayload = JSON.parse(Buffer.from(payloadPart, 'base64').toString())
|
||||
|
||||
@@ -119,14 +121,17 @@ export async function setSessionAction(accessToken: string, refreshToken: string
|
||||
maxAge: 60 * 15
|
||||
})
|
||||
|
||||
cookieStore.set('refresh_token', refreshToken, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
domain: cookieDomain,
|
||||
maxAge: 60 * 60 * 24 * 30
|
||||
})
|
||||
// * Only update refresh token if provided
|
||||
if (refreshToken) {
|
||||
cookieStore.set('refresh_token', refreshToken, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
domain: cookieDomain,
|
||||
maxAge: 60 * 60 * 24 * 30
|
||||
})
|
||||
}
|
||||
|
||||
console.log('[setSessionAction] Cookies set successfully')
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ export default function LayoutContent({ children }: { children: React.ReactNode
|
||||
|
||||
const handleSwitchWorkspace = async (orgId: string) => {
|
||||
try {
|
||||
const { token, refresh_token } = await switchContext(orgId)
|
||||
await setSessionAction(token, refresh_token)
|
||||
const { access_token } = await switchContext(orgId)
|
||||
await setSessionAction(access_token)
|
||||
window.location.reload()
|
||||
} catch (err) {
|
||||
console.error('Failed to switch workspace', err)
|
||||
|
||||
Reference in New Issue
Block a user