-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth check): improve log out flow
- Loading branch information
1 parent
872cb84
commit 4f9a766
Showing
2 changed files
with
34 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters