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
|
// Verify if user is logged in before accessing certain routes
|
||||||
if (to.meta.requiresAuth) {
|
if (to.meta.requiresAuth) {
|
||||||
if (!authService.isLoggedIn.value && !(await authService.loadUser())) {
|
if (!authService.isLoggedIn.value && !(await authService.loadUser())) {
|
||||||
|
const path = to.fullPath
|
||||||
|
if (path !== "/") {
|
||||||
|
localStorage.setItem("redirectAfterLogin", path);
|
||||||
|
}
|
||||||
next("/login");
|
next("/login");
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -10,10 +10,21 @@
|
||||||
|
|
||||||
const errorMessage: Ref<string | null> = ref(null);
|
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 () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
await auth.handleLoginCallback();
|
await auth.handleLoginCallback();
|
||||||
await router.replace("/user"); // Redirect to theme page
|
await redirectPage();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorMessage.value = `${t("loginUnexpectedError")}: ${error}`;
|
errorMessage.value = `${t("loginUnexpectedError")}: ${error}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue