@@ -6,18 +6,29 @@ import { makeWebSocket } from './websocket';
6
6
import { makeCapTPConnection } from './captp' ;
7
7
8
8
// Fetch the access token from the window's URL.
9
- const accessTokenParams = `?${ window . location . hash . slice ( 1 ) } ` ;
10
- if ( isProduction ) {
11
- // Now that we've captured it, clear out the access token from the URL bar.
12
- window . location . hash = '' ;
13
- window . addEventListener ( 'hashchange' , _ev => {
14
- // Keep it clear.
15
- window . location . hash = '' ;
16
- } ) ;
17
- }
18
- const hasAccessToken = new URLSearchParams ( accessTokenParams ) . has (
9
+ let accessTokenParams = `?${ window . location . hash . slice ( 1 ) } ` ;
10
+ let hasAccessToken = new URLSearchParams ( accessTokenParams ) . get (
19
11
'accessToken' ,
20
12
) ;
13
+ try {
14
+ if ( hasAccessToken ) {
15
+ // Store the access token for later use.
16
+ localStorage . setItem ( 'accessTokenParams' , accessTokenParams ) ;
17
+ } else {
18
+ // Try reviving it from localStorage.
19
+ accessTokenParams = localStorage . getItem ( 'accessTokenParams' ) || '?' ;
20
+ hasAccessToken = new URLSearchParams ( accessTokenParams ) . get ( 'accessToken' ) ;
21
+ }
22
+ } catch ( e ) {
23
+ console . log ( 'Error fetching accessTokenParams' , e ) ;
24
+ }
25
+
26
+ // Now that we've captured it, clear out the access token from the URL bar.
27
+ window . location . hash = '' ;
28
+ window . addEventListener ( 'hashchange' , _ev => {
29
+ // Keep it clear.
30
+ window . location . hash = '' ;
31
+ } ) ;
21
32
22
33
if ( ! hasAccessToken ) {
23
34
// This is friendly advice to the user who doesn't know.
0 commit comments