111 lines
2.8 KiB
Vue
111 lines
2.8 KiB
Vue
<template>
|
|
<div>
|
|
<h1 class="sr-only">{{ name }}</h1>
|
|
<div
|
|
v-if="auth.accountChanged && route.meta.requiresAuth && !blocked"
|
|
class="message"
|
|
role="status"
|
|
>
|
|
{{ $t("files.loading") }}
|
|
</div>
|
|
<SessionGate v-else-if="blocked" />
|
|
<router-view v-else :key="auth.epoch"></router-view>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
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.accountChanged,
|
|
(changed) => {
|
|
if (changed && route.meta.requiresAuth)
|
|
void router.replace({ path: "/files/", force: true });
|
|
}
|
|
);
|
|
watch(
|
|
() => auth.user?.perm.admin,
|
|
(admin) => {
|
|
if (admin === false && !auth.accountChanged && 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(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
|
|
const loading = document.getElementById("loading");
|
|
loading?.classList.add("done");
|
|
|
|
setTimeout(function () {
|
|
loading?.parentNode?.removeChild(loading);
|
|
}, 200);
|
|
});
|
|
|
|
// handles ltr/rtl changes
|
|
watch(locale, (newValue) => {
|
|
newValue && setHtmlLocale(newValue);
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.sr-only {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
padding: 0;
|
|
margin: -1px;
|
|
overflow: hidden;
|
|
clip: rect(0, 0, 0, 0);
|
|
white-space: nowrap;
|
|
border: 0;
|
|
}
|
|
</style>
|