mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-20 19:57:44 +02:00
Refresh user preferences from back-end when entering the Options view
This commit is contained in:
parent
f2d4c43239
commit
300d3c3dc8
9
resources/js/services/userService.js
vendored
9
resources/js/services/userService.js
vendored
@ -4,6 +4,15 @@ const apiClient = httpClientFactory('api')
|
||||
const webClient = httpClientFactory('web')
|
||||
|
||||
export default {
|
||||
/**
|
||||
* Get current signed-in user preferences
|
||||
*
|
||||
* @returns promise
|
||||
*/
|
||||
getPreferences(config = {}) {
|
||||
return apiClient.get('/user/preferences', { ...config })
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a user preference
|
||||
*
|
||||
|
18
resources/js/stores/user.js
vendored
18
resources/js/stores/user.js
vendored
@ -1,5 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import authService from '@/services/authService'
|
||||
import userService from '@/services/userService'
|
||||
import router from '@/router'
|
||||
import { useColorMode } from '@vueuse/core'
|
||||
import { useTwofaccounts } from '@/stores/twofaccounts'
|
||||
@ -108,7 +109,6 @@ export const useUserStore = defineStore({
|
||||
mode.value = this.preferences.theme == 'system' ? 'auto' : this.preferences.theme
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Applies user language
|
||||
*/
|
||||
@ -121,13 +121,27 @@ export const useUserStore = defineStore({
|
||||
else loadLanguageAsync('en')
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Applies both user theme & language
|
||||
*/
|
||||
applyUserPrefs() {
|
||||
this.applyTheme()
|
||||
this.applyLanguage()
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh user preferences with backend state
|
||||
*/
|
||||
refreshPreferences() {
|
||||
userService.getPreferences({returnError: true})
|
||||
.then(response => {
|
||||
response.data.forEach(preference => {
|
||||
this.preferences[preference.key] = preference.value
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
notify.alert({ text: trans('errors.data_cannot_be_refreshed_from_server') })
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -78,6 +78,8 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
user.refreshPreferences()
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -65,4 +65,5 @@ return [
|
||||
'sso_no_register' => 'Registrations are disabled',
|
||||
'sso_email_already_used' => 'A user account with the same email address already exists but it does not match your external account ID. Do not use SSO if you are already registered on 2FAuth with this email.',
|
||||
'account_managed_by_external_provider' => 'Account managed by an external provider',
|
||||
'data_cannot_be_refreshed_from_server' => 'Data cannot be refreshed from server'
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user