fix: replace window.location.reload with router.refresh on org switch to prevent hydration errors
This commit is contained in:
@@ -78,11 +78,17 @@ function LayoutInner({ children }: { children: React.ReactNode }) {
|
|||||||
const handleSwitchOrganization = async (orgId: string | null) => {
|
const handleSwitchOrganization = async (orgId: string | null) => {
|
||||||
if (!orgId) return
|
if (!orgId) return
|
||||||
try {
|
try {
|
||||||
|
setIsSwitchingOrg(true)
|
||||||
const { access_token } = await switchContext(orgId)
|
const { access_token } = await switchContext(orgId)
|
||||||
await setSessionAction(access_token)
|
await setSessionAction(access_token)
|
||||||
sessionStorage.setItem(ORG_SWITCH_KEY, 'true')
|
router.refresh()
|
||||||
window.location.reload()
|
// Allow time for server components to re-fetch with new auth
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsSwitchingOrg(false)
|
||||||
|
router.push('/')
|
||||||
|
}, 600)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
setIsSwitchingOrg(false)
|
||||||
logger.error('Failed to switch organization', err)
|
logger.error('Failed to switch organization', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user