File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -38,13 +38,15 @@ let tokens:
3838 | null // Initialized but not logged in
3939 | undefined ; // Not initialized
4040
41- // Synchronously load & parse the latest token value we have, if any
42- try {
43- // ! because actually parse(null) -> null, so it's ok
44- tokens = JSON . parse ( localStorage . getItem ( 'tokens' ) ! ) ;
45- } catch ( e ) {
46- tokens = null ;
47- console . log ( 'Invalid token' , localStorage . getItem ( 'tokens' ) , e ) ;
41+ if ( typeof localStorage !== 'undefined' ) { // Skip this in SSR or other non-persistent envs
42+ // Synchronously load & parse the latest token value we have, if any
43+ try {
44+ // ! because actually parse(null) -> null, so it's ok
45+ tokens = JSON . parse ( localStorage . getItem ( 'tokens' ) ! ) ;
46+ } catch ( e ) {
47+ tokens = null ;
48+ console . log ( 'Invalid token' , localStorage . getItem ( 'tokens' ) , e ) ;
49+ }
4850}
4951
5052function setTokens ( newTokens : typeof tokens ) {
You can’t perform that action at this time.
0 commit comments