Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart: improve login flow #19084

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions assets/js/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 6 additions & 1 deletion assets/js/components/HelpModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions assets/js/components/LoginModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading