Fix kicker triggering & Show a notification when kicked-out

This commit is contained in:
Bubka 2023-11-15 17:01:51 +01:00
parent 3778977c94
commit 26511954c4
7 changed files with 16 additions and 11 deletions

View File

@ -36,7 +36,7 @@
function protectedRoute(route) { function protectedRoute(route) {
let bool = false let bool = false
route.meta.middlewares?.forEach(func => { route.meta.middlewares?.forEach(func => {
if (func instanceof Function && func.name == 'auth') { if (func instanceof Function && func.name == 'authGuard') {
bool = true bool = true
return return
} }

View File

@ -42,11 +42,12 @@
// }, 1000); // }, 1000);
} }
// Triggers the user logout
function logoutUser() { function logoutUser() {
clearTimeout(logoutTimer.value) clearTimeout(logoutTimer.value)
console.log('inativity detected, user kicked out') console.log('inativity detected, user kicked out')
user.logout() user.logout({ kicked: true})
} }
function resetTimer() { function resetTimer() {

View File

@ -212,7 +212,7 @@
if (copied) { if (copied) {
if(user.preferences.kickUserAfter == -1 && (permit_closing || false) === true) { if(user.preferences.kickUserAfter == -1 && (permit_closing || false) === true) {
user.logout() user.logout({ kicked: true})
} }
else if(user.preferences.closeOtpOnCopy && (permit_closing || false) === true) { else if(user.preferences.closeOtpOnCopy && (permit_closing || false) === true) {
emit("please-close-me"); emit("please-close-me");

View File

@ -78,7 +78,7 @@ export const httpClientFactory = (endpoint = 'api') => {
// We catch the 418 response and log the user out // We catch the 418 response and log the user out
if (error.response.status === 418) { if (error.response.status === 418) {
const user = useUserStore() const user = useUserStore()
user.logout() user.logout({ kicked: true})
} }
useNotifyStore().error(error) useNotifyStore().error(error)

View File

@ -4,6 +4,7 @@ import router from '@/router'
import { useColorMode } from '@vueuse/core' import { useColorMode } from '@vueuse/core'
import { useTwofaccounts } from '@/stores/twofaccounts' import { useTwofaccounts } from '@/stores/twofaccounts'
import { useGroups } from '@/stores/groups' import { useGroups } from '@/stores/groups'
import { useNotifyStore } from '@/stores/notify'
export const useUserStore = defineStore({ export const useUserStore = defineStore({
id: 'user', id: 'user',
@ -55,7 +56,9 @@ export const useUserStore = defineStore({
/** /**
* Logs the user out or moves to proxy logout url * Logs the user out or moves to proxy logout url
*/ */
logout() { logout(options = {}) {
const { kicked } = options
// async appLogout(evt) { // async appLogout(evt) {
if (this.$2fauth.config.proxyAuth) { if (this.$2fauth.config.proxyAuth) {
if (this.$2fauth.config.proxyLogoutUrl) { if (this.$2fauth.config.proxyLogoutUrl) {
@ -66,11 +69,13 @@ export const useUserStore = defineStore({
else { else {
return authService.logout().then(() => { return authService.logout().then(() => {
this.reset() this.reset()
if (kicked) {
const notify = useNotifyStore()
notify.clear()
notify.warn({ text: trans('auth.autolock_triggered_punchline'), duration:-1 })
}
}) })
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
} }
// },
}, },
/** /**

View File

@ -166,7 +166,7 @@
if (copied) { if (copied) {
if(user.preferences.kickUserAfter == -1) { if(user.preferences.kickUserAfter == -1) {
user.logout() user.logout({ kicked: true})
} }
notify.success({ text: trans('commons.copied_to_clipboard') }) notify.success({ text: trans('commons.copied_to_clipboard') })
} }

View File

@ -27,8 +27,7 @@
'register' => 'Register', 'register' => 'Register',
'welcome_to_2fauth' => 'Welcome to 2FAuth', 'welcome_to_2fauth' => 'Welcome to 2FAuth',
'autolock_triggered' => 'Auto lock triggered', 'autolock_triggered' => 'Auto lock triggered',
'autolock_triggered_punchline' => 'The event watched by the Auto Lock feature has fired. You\'ve been automatically disconnected.', 'autolock_triggered_punchline' => 'You\'ve been automatically disconnected.',
'change_autolock_in_settings' => 'You can change the behavior of the Autolock feature in Settings > Options tab.',
'already_authenticated' => 'Already authenticated, please log out first', 'already_authenticated' => 'Already authenticated, please log out first',
'authentication' => 'Authentication', 'authentication' => 'Authentication',
'maybe_later' => 'Maybe later', 'maybe_later' => 'Maybe later',