productdevbook
01/03/2023, 3:21 PMts
<script setup lang="ts">
import * as Session from 'supertokens-web-js/recipe/session'
onMounted(async () => {
if (await Session.doesSessionExist()) {
// since a session already exists, we redirect the user to the HomeView.vue component
window.location.assign('/home')
}
})
</script>
<template>
<IonPage>
<IonRouterOutlet id="main" />
</IonPage>
</template>
rp_st
01/03/2023, 3:22 PMrp_st
01/03/2023, 3:22 PMdoesSessionExist
on each page load / route change?rp_st
01/03/2023, 3:22 PMrp_st
01/03/2023, 3:23 PMproductdevbook
01/03/2023, 3:23 PMrp_st
01/03/2023, 3:23 PMrp_st
01/03/2023, 3:23 PM/auth
pageproductdevbook
01/03/2023, 3:24 PMproductdevbook
01/03/2023, 3:26 PMts
const sessionGuard: NavigationGuard = async (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
) => {
if (await Session.doesSessionExist()) {
// Session exists
next('/auth')
}
else {
next()
}
}
export const onBeforeEach: NavigationGuard = async (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
) => {
await sessionGuard(to, from, next)
}
add vue router.tsrp_st
01/03/2023, 3:28 PMproductdevbook
01/03/2023, 3:28 PMproductdevbook
01/03/2023, 3:28 PMrp_st
01/03/2023, 3:28 PMrp_st
01/03/2023, 3:28 PMrp_st
01/03/2023, 3:29 PMproductdevbook
01/04/2023, 6:16 PMts
export const sessionGuard: NavigationGuard = async (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext,
) => {
const sessionExists = await Session.doesSessionExist()
if (sessionExists) {
if (await checkIfCookieExists()) {
if (to.meta.auth === 'private')
return next()
else
return next('/home')
}
return next()
}
else {
const sessionExists = await Session.doesSessionExist()
if (to.meta.auth === 'onboard' && !sessionExists)
return next()
else
return next('/auth')
}
}
productdevbook
01/04/2023, 6:17 PMawait Session
, I get a white screen and the next time it doesn't start, the router breaks.rp_st
01/04/2023, 6:17 PMproductdevbook
01/04/2023, 6:18 PMrp_st
01/04/2023, 6:18 PMproductdevbook
01/04/2023, 6:18 PMrp_st
01/04/2023, 6:18 PMproductdevbook
01/04/2023, 6:20 PMproductdevbook
01/04/2023, 6:21 PMrp_st
01/04/2023, 6:23 PMproductdevbook
01/04/2023, 6:31 PMproductdevbook
01/04/2023, 6:31 PMrp_st
01/04/2023, 6:32 PM