feat: onthou link voor redirect naar login
This commit is contained in:
parent
6997e29da1
commit
c0b0e01eea
2 changed files with 16 additions and 1 deletions
|
@ -143,6 +143,10 @@ router.beforeEach(async (to, _from, next) => {
|
|||
// Verify if user is logged in before accessing certain routes
|
||||
if (to.meta.requiresAuth) {
|
||||
if (!authService.isLoggedIn.value && !(await authService.loadUser())) {
|
||||
const path = to.fullPath
|
||||
if (path !== "/") {
|
||||
localStorage.setItem("redirectAfterLogin", path);
|
||||
}
|
||||
next("/login");
|
||||
} else {
|
||||
next();
|
||||
|
|
|
@ -10,10 +10,21 @@
|
|||
|
||||
const errorMessage: Ref<string | null> = ref(null);
|
||||
|
||||
async function redirectPage() {
|
||||
const redirectUrl = localStorage.getItem("redirectAfterLogin");
|
||||
if (redirectUrl) {
|
||||
console.log("redirect", redirectUrl);
|
||||
localStorage.removeItem("redirectAfterLogin");
|
||||
await router.replace(redirectUrl);
|
||||
} else {
|
||||
await router.replace("/user"); // Redirect to theme page
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await auth.handleLoginCallback();
|
||||
await router.replace("/user"); // Redirect to theme page
|
||||
await redirectPage();
|
||||
} catch (error) {
|
||||
errorMessage.value = `${t("loginUnexpectedError")}: ${error}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue