Skip to content

Commit

Permalink
feat(auth check): improve log out flow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Mar 30, 2024
1 parent 872cb84 commit 4f9a766
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
51 changes: 24 additions & 27 deletions middleware/auth-check.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
export default defineNuxtRouteMiddleware((to, from) => {
if (!process.client) {
return
}

if (!process.client) {
return
}

const { $auth, $pocketBase } = useNuxtApp()

if (($auth.loggedIn && !$pocketBase.authStore.isValid) || (!$auth.loggedIn && $pocketBase.authStore.isValid)) {

// Log out from pocketbase
$pocketBase.authStore.clear()
const { $auth, $pocketBase } = useNuxtApp()

let authCookie
authCookie = useCookie('auth.strategy')
authCookie.value = undefined
if (($auth.loggedIn && !$pocketBase.authStore.isValid) || (!$auth.loggedIn && $pocketBase.authStore.isValid)) {
// Log out from pocketbase
$pocketBase.authStore.clear()

authCookie = useCookie('auth._token.local')
authCookie.value = undefined
authCookie = useCookie('auth._token_expiration.local')
authCookie.value = undefined
let authCookie
authCookie = useCookie('auth.strategy')
authCookie.value = undefined

authCookie = useCookie('auth._refresh_token.local')
authCookie.value = undefined
authCookie = useCookie('auth._refresh_token_expiration.local')
authCookie.value = undefined
authCookie = useCookie('auth._token.local')
authCookie.value = undefined
authCookie = useCookie('auth._token_expiration.local')
authCookie.value = undefined

// Log out from API
// TODO: Restore when it works
// await _signOut()
authCookie = useCookie('auth._refresh_token.local')
authCookie.value = undefined
authCookie = useCookie('auth._refresh_token_expiration.local')
authCookie.value = undefined

window.location.reload()
}
// Log out from API
// TODO: Restore when it works
// await _signOut()

window.location.href = '/premium/sign-in?message=Failed to authenticate. Please sign in again.'
}

return
return
})
11 changes: 10 additions & 1 deletion pages/premium/sign-in.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
await navigateTo('/premium/dashboard')
}
onNuxtReady(() => {
const route = useRoute()
const message = route.query.message
if (message) {
toast.info(message)
}
})
useSeoMeta({
title: 'Sign in',
Expand Down Expand Up @@ -92,8 +101,8 @@
<NuxtLink
class="hover:hover-text-util focus-visible:focus-outline-util font-semibold"
href="https://app.gumroad.com/library?query=Rule+34+App"
target="_blank"
rel="nofollow noopener noreferrer"
target="_blank"
>
Forgot license?
</NuxtLink>
Expand Down

0 comments on commit 4f9a766

Please sign in to comment.