-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathapp.vue
50 lines (47 loc) · 1.3 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<template>
<div>
<NuxtErrorBoundary @error="mHandleError">
<NuxtLayout v-if="shouldRender">
<NuxtPage />
</NuxtLayout>
</NuxtErrorBoundary>
</div>
</template>
<script setup lang="ts">
import { watchEffect } from "vue";
import { useAuthUser } from "~/store/auth";
const authStore = useAuthUser();
const route = useRoute();
const mHandleError = (e: any) => {
logger.error("Primary error boundary", e);
};
const shouldRender = computed(
() => !authStore.isPending || authStore.isAuthenticated
);
// Doing this here instead than in the middleware allow reactivity on the auth user
watchEffect(async () => {
logger.info("pending");
if (authStore.isPending) {
return;
}
logger.info("resolved pending");
const shouldRedirectToLogin =
!authStore.isAuthenticated &&
authStore.authUrl &&
route.name !== "auth-login";
logger.info("shouldRedirectToLogin");
logger.info(authStore.isAuthenticated);
logger.info(authStore.authUrl);
logger.info(route.name);
logger.info(shouldRedirectToLogin);
if (shouldRedirectToLogin) {
await navigateTo(authStore.authUrl, { external: true });
}
const shouldRedirectToHomepage =
authStore.isAuthenticated && route.name === "auth-login";
if (shouldRedirectToHomepage) {
await navigateTo("/");
}
});
</script>
cd