MCPcopy Create free account
hub / github.com/error311/FileRise / checkAuthentication

Function checkAuthentication

public/js/auth.js:495–563  ·  view source on GitHub ↗
(showLoginToast = true)

Source from the content-addressed store, hash-verified

493}
494
495function checkAuthentication(showLoginToast = true) {
496 return sendRequest("/api/auth/checkAuth.php")
497 .then(data => {
498 if (data.setup) {
499 const overlay = document.getElementById('loadingOverlay');
500 if (overlay) overlay.remove();
501
502 // keep app shell hidden during setup
503 const wrap = document.querySelector('.main-wrapper');
504 if (wrap) {
505 wrap.setAttribute('hidden', '');
506 wrap.style.display = 'none';
507 }
508 document.getElementById('loginForm').style.display = 'none';
509 window.setupMode = true;
510 if (showLoginToast) showToast(t('setup_no_users'));
511 toggleVisibility("loginForm", false);
512 toggleVisibility("mainOperations", false);
513 document.querySelector(".header-buttons").style.visibility = "hidden";
514 toggleVisibility("addUserModal", true);
515 document.getElementById("newUsername").focus();
516 return false;
517 }
518 window.setupMode = false;
519 if (data.authenticated) {
520
521 localStorage.setItem('isAdmin', data.isAdmin ? 'true' : 'false');
522 localStorage.setItem("folderOnly", data.folderOnly);
523 localStorage.setItem("readOnly", data.readOnly);
524 localStorage.setItem("disableUpload", data.disableUpload);
525 updateLoginOptionsUIFromStorage();
526 applyProxyBypassUI();
527 if (typeof data.totp_enabled !== "undefined") {
528 localStorage.setItem("userTOTPEnabled", data.totp_enabled ? "true" : "false");
529 }
530 if (data.csrf_token) {
531 window.csrfToken = data.csrf_token;
532 document.querySelector('meta[name="csrf-token"]').content = data.csrf_token;
533 }
534 updateAuthenticatedUI(data);
535 return data;
536
537 // at the end of updateAuthenticatedUI(data)
538 if (!window.__FR_FLAGS?.initialized && typeof initializeApp === 'function') {
539 initializeApp();
540 window.__FR_FLAGS.initialized = true;
541 }
542 if (typeof applyTranslations === 'function') applyTranslations();
543 if (typeof updateLoginOptionsUIFromStorage === 'function') updateLoginOptionsUIFromStorage();
544 } else {
545 const overlay = document.getElementById('loadingOverlay');
546 if (overlay) overlay.remove();
547
548 // show the wrapper (so the login form can be visible)
549 document.querySelector('.main-wrapper').style.display = '';
550 document.getElementById('loginForm').style.display = '';
551 if (showLoginToast) showToast(t('please_log_in_to_continue'));
552 toggleVisibility("loginForm", !(localStorage.getItem("authBypass") === "true"));

Callers 1

initAuthFunction · 0.85

Calls 9

tFunction · 0.85
toggleVisibilityFunction · 0.85
applyProxyBypassUIFunction · 0.85
updateAuthenticatedUIFunction · 0.85
initializeAppFunction · 0.85
applyTranslationsFunction · 0.85
sendRequestFunction · 0.70
showToastFunction · 0.70

Tested by

no test coverage detected