-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove suspense boundary from token refresh.
- Loading branch information
1 parent
24d28fb
commit 10bd78a
Showing
2 changed files
with
54 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { useSetAtom } from 'jotai'; | ||
import { ChromeUserConfig, initChromeUserConfig } from '../utils/initUserConfig'; | ||
import { isPreviewAtom } from '../state/atoms/releaseAtom'; | ||
import { userConfigAtom } from '../state/atoms/userConfigAtom'; | ||
import ChromeAuthContext from '../auth/ChromeAuthContext'; | ||
|
||
const useSessionConfig = () => { | ||
const [configLoaded, setConfigLoaded] = useState(false); | ||
const { getUser, token } = useContext(ChromeAuthContext); | ||
const initPreview = useSetAtom(isPreviewAtom); | ||
const setUserConfig = useSetAtom(userConfigAtom); | ||
function initSuccess(userConfig: ChromeUserConfig) { | ||
if (!configLoaded) { | ||
// do not re-initialize preview if already loaded | ||
// it can "restart" active user sessions. Because toggling preview re-rendes the UI modules, it can cause issues | ||
initPreview(userConfig.data.uiPreview); | ||
} | ||
setUserConfig(userConfig); | ||
} | ||
function initFail() { | ||
initPreview(false); | ||
} | ||
|
||
async function initConfig() { | ||
try { | ||
const config = await initChromeUserConfig({ getUser, token }); | ||
initSuccess(config); | ||
setConfigLoaded(true); | ||
} catch (error) { | ||
initFail(); | ||
throw error; | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
initConfig(); | ||
}, [getUser, token]); | ||
|
||
return configLoaded; | ||
}; | ||
|
||
export default useSessionConfig; |