feat: adopt shared internal SSO sessions and add no-sso launch mode

This commit is contained in:
SantaSpeen committed 2026-10-24 15:41:39 +03:00
1 parent c209f1effc
commit c02bf755f2
51 files changed
+2131 -362

No files matched your search

+57 -3
View File
@@ -1,22 +1,76 @@
<template>
<div>
<h1 class="sr-only">{{ name }}</h1>
<router-view></router-view>
<SessionGate v-if="blocked" />
<router-view v-else :key="auth.epoch"></router-view>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { ref, onMounted, onBeforeUnmount, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { setHtmlLocale } from "./i18n";
import { getMediaPreference, getTheme, setTheme } from "./utils/theme";
import { name } from "./utils/constants";
import { useRoute, useRouter } from "vue-router";
import { useAuthStore } from "@/stores/auth";
import { acceptSession, setSessionRecheck } from "@/utils/auth";
import SessionGate from "@/components/SessionGate.vue";
import "@/utils/internal-session.js";
import { baseURL, noAuth } from "@/utils/constants";
const auth = useAuthStore(),
route = useRoute(),
router = useRouter();
watch(
() => auth.user?.id,
(id, old) => {
if (id && old && id !== old && route.meta.requiresAuth)
void router.replace("/files/");
}
);
watch(
() => auth.user?.perm.admin,
(admin) => {
if (admin === false && route.meta.requiresAdmin)
void router.replace("/403");
}
);
const blocked = computed(
() =>
!["Login", "Share"].includes(String(route.name)) &&
auth.sessionStatus !== "authenticated"
);
let sync: { stop: () => void } | undefined;
onBeforeUnmount(() => {
sync?.stop();
setSessionRecheck();
});
const { locale } = useI18n();
const userTheme = ref<UserTheme>(getTheme() || getMediaPreference());
onMounted(() => {
onMounted(async () => {
await router.isReady();
if (
!noAuth &&
window.FileBrowser.SSOIssuer &&
window.FileBrowser.SSOClientID
) {
const restart = () => {
sync?.stop();
sync = window.SSOInternalSession.start({
issuer: window.FileBrowser.SSOIssuer,
clientId: window.FileBrowser.SSOClientID,
checkUrl: baseURL + "/auth/session",
onChange: acceptSession,
onUnavailable: () =>
acceptSession({ status: "unavailable", authenticated: false }),
});
};
restart();
setSessionRecheck(restart);
}
setTheme(userTheme.value, false);
setHtmlLocale(locale.value);
// this might be null during HMR