Skip to content

Commit

Permalink
fix: only fetch 'self' once
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Stanley <[email protected]>
  • Loading branch information
lrstanley committed Sep 1, 2022
1 parent a502b22 commit 912d537
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions public/src/lib/core/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ const router = createRouter({
routes,
})

// Only try and fetch self once.
const gotSelf = ref(false)

router.beforeEach(async (to, from, next) => {
if (from.name != to.name || JSON.stringify(from.params) != JSON.stringify(to.params)) {
loadingBar.start()
}

const state = useState()
if (!state.hasSelf) {
if (!state.hasSelf && !gotSelf.value) {
// Kickoff the request for /api/self to lookup the user, in the background.
api.lookup
.getAddress({ address: "self" })
.then((result) => {
saveResult(result)
})
.catch(() => null)
.catch(() => (gotSelf.value = true))
} else {
gotSelf.value = true
}

next()
Expand Down

0 comments on commit 912d537

Please sign in to comment.