Skip to content

Commit

Permalink
refactor(auth): remove extra token check
Browse files Browse the repository at this point in the history
If `firstTime` is "true" then the token cannot defined.
  • Loading branch information
becem-gharbi committed Mar 9, 2024
1 parent 41fbc4c commit c9fa3c7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/runtime/plugins/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
const firstTime = (process.server && !isPrerenderd) || (process.client && (!isServerRendered || isPrerenderd))

if (firstTime) {
if (token.value) {
await useDirectusAuth().fetchUser()
} else {
const isCallback = useRoute().path === config.auth.redirect.callback
const { _refreshToken, refresh } = useDirectusSession()
const isCallback = useRoute().path === config.auth.redirect.callback
const { _refreshToken, refresh } = useDirectusSession()

if (isCallback || _loggedInFlag.value || _refreshToken.get()) {
await refresh()
if (token.value) {
await useDirectusAuth().fetchUser()
}
if (isCallback || _loggedInFlag.value || _refreshToken.get()) {
await refresh()
if (token.value) {
await useDirectusAuth().fetchUser()
}
}
}
Expand Down

0 comments on commit c9fa3c7

Please sign in to comment.