Skip to content

Commit

Permalink
Merge pull request #1403 from rommapp/fix/infinite-redirection-loop
Browse files Browse the repository at this point in the history
fix: infinite redirection loop on setup
  • Loading branch information
zurdi15 authored Dec 27, 2024
2 parents 3139290 + f8f639b commit 35a208f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
40 changes: 22 additions & 18 deletions frontend/src/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,29 @@ router.beforeEach(async (to, _from, next) => {
const heartbeat = storeHeartbeat();
const auth = storeAuth();
const { user } = storeToRefs(auth);
if (heartbeat.value.SHOW_SETUP_WIZARD && to.name !== "setup") {

if (heartbeat.value.SHOW_SETUP_WIZARD && to.name?.toString() !== "setup") {
next({ name: "setup" });
}
if (
(to.name == "login" && user.value && !heartbeat.value.SHOW_SETUP_WIZARD) ||
(to.name == "setup" && !heartbeat.value.SHOW_SETUP_WIZARD)
) {
next({ name: "home" });
} else if (to.name !== "login" && !user.value) {
next({ name: "login" });
} else if (
to.name &&
user.value &&
((["scan", "management"].includes(to.name.toString()) &&
!user.value.oauth_scopes.includes("platforms.write")) ||
(["administration"].includes(to.name.toString()) &&
!user.value.oauth_scopes.includes("users.write")))
) {
next({ name: "404" });
} else if (!heartbeat.value.SHOW_SETUP_WIZARD) {
if (
(to.name?.toString() === "login" || to.name?.toString() === "setup") &&
user.value
) {
next({ name: "home" });
} else if (to.name?.toString() !== "login" && !user.value) {
next({ name: "login" });
} else if (
to.name &&
user.value &&
((["scan", "management"].includes(to.name.toString()) &&
!user.value.oauth_scopes.includes("platforms.write")) ||
(["administration"].includes(to.name.toString()) &&
!user.value.oauth_scopes.includes("users.write")))
) {
next({ name: "404" });
} else {
next();
}
} else {
next();
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/views/Auth/Setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import router from "@/plugins/router";
import { refetchCSRFToken } from "@/services/api/index";
import userApi from "@/services/api/user";
import api from "@/services/api/index";
import storeHeartbeat from "@/stores/heartbeat";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
Expand Down Expand Up @@ -55,7 +56,10 @@ async function finishWizard() {
.createUser(defaultAdminUser.value)
.then(async () => {
await refetchCSRFToken();
router.push({ name: "login" });
await api.get("/heartbeat").then(({ data: heartbeatData }) => {
heartbeat.set(heartbeatData);
router.push({ name: "login" });
});
})
.catch(({ response, message }) => {
emitter?.emit("snackbarShow", {
Expand Down

0 comments on commit 35a208f

Please sign in to comment.