Skip to content

Commit 20d7c58

Browse files
committed
Replace authenticateOnStartup with waitForInitialSession
1 parent cfd9ff2 commit 20d7c58

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
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';
44
import { ref, watch } from 'vue';
55
import { useVanillaCss } from './lib/shared-globals';
66
import { frameworkStyles } from './lib/framework-styles';
@@ -14,7 +14,7 @@ watch(router.currentRoute, route => {
1414
useVanillaCss.value = true;
1515
});
1616
17-
authenticateOnStartup();
17+
waitForInitialSession();
1818
1919
</script>
2020

src/lib/atproto/signed-in-user.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ function isTokenUsable({ token }: Session): boolean {
9797
return expires == null || Date.now() + 60_000 <= expires;
9898
}
9999

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+
})();
105109
}
110+
111+
await initialSessionPromise;
106112
}

0 commit comments

Comments
 (0)