mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-09-20 05:10:27 +00:00
fix: show login when session token expires
This commit is contained in:
parent
4ff247e134
commit
e6c674b3c6
@ -45,6 +45,15 @@
|
|||||||
animation: 0.2s opac forwards;
|
animation: 0.2s opac forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#login .logout-message {
|
||||||
|
background: var(--icon-orange);
|
||||||
|
color: #fff;
|
||||||
|
padding: 0.5em;
|
||||||
|
text-align: center;
|
||||||
|
animation: 0.2s opac forwards;
|
||||||
|
text-transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes opac {
|
@keyframes opac {
|
||||||
0% {
|
0% {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
@ -101,7 +101,10 @@
|
|||||||
"submit": "Login",
|
"submit": "Login",
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"usernameTaken": "Username already taken",
|
"usernameTaken": "Username already taken",
|
||||||
"wrongCredentials": "Wrong credentials"
|
"wrongCredentials": "Wrong credentials",
|
||||||
|
"logout_reasons": {
|
||||||
|
"inactivity": "You have been logged out due to inactivity."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"permanent": "Permanent",
|
"permanent": "Permanent",
|
||||||
"prompts": {
|
"prompts": {
|
||||||
|
@ -7,9 +7,11 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
state: (): {
|
state: (): {
|
||||||
user: IUser | null;
|
user: IUser | null;
|
||||||
jwt: string;
|
jwt: string;
|
||||||
|
logoutTimer: number | null;
|
||||||
} => ({
|
} => ({
|
||||||
user: null,
|
user: null,
|
||||||
jwt: "",
|
jwt: "",
|
||||||
|
logoutTimer: null,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
// user and jwt getter removed, no longer needed
|
// user and jwt getter removed, no longer needed
|
||||||
@ -37,5 +39,8 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
clearUser() {
|
clearUser() {
|
||||||
this.$reset();
|
this.$reset();
|
||||||
},
|
},
|
||||||
|
setLogoutTimer(logoutTimer: number | null) {
|
||||||
|
this.logoutTimer = logoutTimer;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -16,6 +16,17 @@ export function parseToken(token: string) {
|
|||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
authStore.jwt = token;
|
authStore.jwt = token;
|
||||||
authStore.setUser(data.user);
|
authStore.setUser(data.user);
|
||||||
|
|
||||||
|
if (authStore.logoutTimer) {
|
||||||
|
clearTimeout(authStore.logoutTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
const expiresAt = new Date(data.exp! * 1000);
|
||||||
|
authStore.setLogoutTimer(
|
||||||
|
window.setTimeout(() => {
|
||||||
|
logout("inactivity");
|
||||||
|
}, expiresAt.getTime() - Date.now())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validateLogin() {
|
export async function validateLogin() {
|
||||||
@ -92,7 +103,7 @@ export async function signup(username: string, password: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logout() {
|
export function logout(reason?: string) {
|
||||||
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict;";
|
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict;";
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
@ -102,6 +113,15 @@ export function logout() {
|
|||||||
if (noAuth) {
|
if (noAuth) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
router.push({ path: "/login" });
|
if (typeof reason === "string" && reason.trim() !== "") {
|
||||||
|
router.push({
|
||||||
|
path: "/login",
|
||||||
|
query: { "logout-reason": reason },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
router.push({
|
||||||
|
path: "/login",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
<form @submit="submit">
|
<form @submit="submit">
|
||||||
<img :src="logoURL" alt="File Browser" />
|
<img :src="logoURL" alt="File Browser" />
|
||||||
<h1>{{ name }}</h1>
|
<h1>{{ name }}</h1>
|
||||||
|
<p v-if="reason != null" class="logout-message">
|
||||||
|
{{ t(`login.logout_reasons.${reason}`) }}
|
||||||
|
</p>
|
||||||
<div v-if="error !== ''" class="wrong">{{ error }}</div>
|
<div v-if="error !== ''" class="wrong">{{ error }}</div>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
@ -70,6 +73,8 @@ const toggleMode = () => (createMode.value = !createMode.value);
|
|||||||
|
|
||||||
const $showError = inject<IToastError>("$showError")!;
|
const $showError = inject<IToastError>("$showError")!;
|
||||||
|
|
||||||
|
const reason = route.query["logout-reason"] ?? null;
|
||||||
|
|
||||||
const submit = async (event: Event) => {
|
const submit = async (event: Event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user