-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve logged-in user after refresh/redirect
- Loading branch information
1 parent
e493b30
commit c11894d
Showing
3 changed files
with
65 additions
and
16 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,25 +1,17 @@ | ||
<script setup lang="ts"> | ||
import { provide, ref } from "vue"; | ||
import Toast from "primevue/toast"; | ||
import { userKey } from "@/arches_lingo/constants.ts"; | ||
import HomePage from "@/arches_lingo/pages/HomePage.vue"; | ||
import LoginPage from "@/arches_lingo/pages/login/LoginPage.vue"; | ||
import type { User } from "@/arches_lingo/types"; | ||
import ProgressSpinner from "primevue/progressspinner"; | ||
const user = ref<User | null>(null); | ||
const setUser = (userToSet: User | null) => { | ||
user.value = userToSet; | ||
}; | ||
provide(userKey, { user, setUser }); | ||
import PageSwitcher from "@/arches_lingo/pages/PageSwitcher.vue"; | ||
</script> | ||
|
||
<template> | ||
<div style="font-family: sans-serif"> | ||
<HomePage v-if="user" /> | ||
<LoginPage v-else /> | ||
</div> | ||
<Suspense> | ||
<PageSwitcher /> | ||
<template #fallback> | ||
<ProgressSpinner style="display: flex; margin-top: 8rem" /> | ||
</template> | ||
</Suspense> | ||
<Toast /> | ||
</template> |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup lang="ts"> | ||
import { provide, ref } from "vue"; | ||
import { useGettext } from "vue3-gettext"; | ||
import { useToast } from "primevue/usetoast"; | ||
import { fetchUser } from "@/arches_lingo/api.ts"; | ||
import { | ||
DEFAULT_ERROR_TOAST_LIFE, | ||
ERROR, | ||
userKey, | ||
} from "@/arches_lingo/constants.ts"; | ||
import HomePage from "@/arches_lingo/pages/HomePage.vue"; | ||
import LoginPage from "@/arches_lingo/pages/login/LoginPage.vue"; | ||
import type { User } from "@/arches_lingo/types"; | ||
const { $gettext } = useGettext(); | ||
const toast = useToast(); | ||
const user = ref<User | null>(null); | ||
const setUser = (userToSet: User | null) => { | ||
user.value = userToSet; | ||
}; | ||
provide(userKey, { user, setUser }); | ||
try { | ||
setUser(await fetchUser()); | ||
} catch (error) { | ||
toast.add({ | ||
severity: ERROR, | ||
life: DEFAULT_ERROR_TOAST_LIFE, | ||
summary: $gettext("Login required"), // most likely case is inactive user | ||
detail: error instanceof Error ? error.message : undefined, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<div style="font-family: sans-serif"> | ||
<HomePage v-if="user && user.username !== 'anonymous'" /> | ||
<LoginPage v-else /> | ||
</div> | ||
</template> |