File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
import { RouterLink , RouterView , useRouter } from ' vue-router' ;
3
- import { authenticateOnStartup } from ' ./lib/atproto/signed-in-user' ;
3
+ import { waitForInitialSession } from ' ./lib/atproto/signed-in-user' ;
4
4
import { ref , watch } from ' vue' ;
5
5
import { useVanillaCss } from ' ./lib/shared-globals' ;
6
6
import { frameworkStyles } from ' ./lib/framework-styles' ;
@@ -14,7 +14,7 @@ watch(router.currentRoute, route => {
14
14
useVanillaCss .value = true ;
15
15
});
16
16
17
- authenticateOnStartup ();
17
+ waitForInitialSession ();
18
18
19
19
</script >
20
20
Original file line number Diff line number Diff line change @@ -97,10 +97,16 @@ function isTokenUsable({ token }: Session): boolean {
97
97
return expires == null || Date . now ( ) + 60_000 <= expires ;
98
98
}
99
99
100
- export function authenticateOnStartup ( ) {
101
- if ( account . value ) { // automatically sign in if possible
102
- authenticateIfNecessary ( account . value . handle , true )
103
- . then ( result =>
104
- console . log ( `early authentication complete: ${ result } ` ) ) ;
100
+ let initialSessionPromise : Promise < void > | undefined ;
101
+ export async function waitForInitialSession ( ) {
102
+ if ( ! initialSessionPromise ) {
103
+ initialSessionPromise = ( async ( ) => {
104
+ if ( account . value ) { // automatically sign in if possible
105
+ const result = await authenticateIfNecessary ( account . value . handle , true ) ;
106
+ console . log ( `early authentication complete: ${ result } ` ) ;
107
+ }
108
+ } ) ( ) ;
105
109
}
110
+
111
+ await initialSessionPromise ;
106
112
}
You can’t perform that action at this time.
0 commit comments