Restart: improve login flow (#19084)

This commit is contained in:
Michael Geers 2025-02-23 11:24:47 +01:00 • committed by GitHub
parent c59f1b1ca7
commit 37fa5345f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 6 deletions

View file

@ -7,7 +7,8 @@ import { isSystemError } from "./utils/fatal";
const auth = reactive({
configured: true,
loggedIn: null, // true / false / null (unknown)
nextUrl: null,
nextUrl: null, // url to navigate to after login
nextModal: null, // modal instance to show after login
});
export async function updateAuthStatus() {
@ -64,8 +65,15 @@ export function getAndClearNextUrl() {
return nextUrl;
}
export function openLoginModal(nextUrl = null) {
export function getAndClearNextModal() {
const nextModal = auth.nextModal;
auth.nextModal = null;
return nextModal;
}
export function openLoginModal(nextUrl = null, nextModal = null) {
auth.nextUrl = nextUrl;
auth.nextModal = nextModal;
const modal = Modal.getOrCreateInstance(document.getElementById("loginModal"));
modal.show();
}

View file

@ -140,6 +140,7 @@
import Modal from "bootstrap/js/dist/modal";
import { docsPrefix } from "../i18n";
import { performRestart } from "../restart";
import { isLoggedIn, openLoginModal } from "../auth";
export default {
name: "HelpModal",
@ -156,7 +157,11 @@ export default {
},
openConfirmRestartModal() {
const modal = Modal.getOrCreateInstance(document.getElementById("confirmRestartModal"));
modal.show();
if (!isLoggedIn()) {
openLoginModal(null, modal);
} else {
modal.show();
}
},
async restartConfirmed() {
await performRestart();

View file

@ -61,7 +61,7 @@
import GenericModal from "./GenericModal.vue";
import Modal from "bootstrap/js/dist/modal";
import api from "../api";
import { updateAuthStatus, getAndClearNextUrl, isLoggedIn } from "../auth";
import { updateAuthStatus, getAndClearNextUrl, getAndClearNextModal, isLoggedIn } from "../auth";
import { docsPrefix } from "../i18n";
export default {
@ -119,8 +119,10 @@ export default {
await updateAuthStatus();
if (isLoggedIn()) {
this.closeModal();
const target = getAndClearNextUrl();
if (target) this.$router.push(target);
const url = getAndClearNextUrl();
if (url) this.$router.push(url);
const modal = getAndClearNextModal();
if (modal) modal.show();
this.password = "";
} else {
// login successful but auth cookie doesnt work