mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Faster frontend authentication.
This commit is contained in:
@@ -490,9 +490,6 @@ router.beforeEach(async (to, from, next) => {
|
||||
const previousPage = window.location.href
|
||||
sessionStorage.setItem('previousPage', previousPage)
|
||||
const authStore = useAuthStore()
|
||||
if (!authStore.authUser) {
|
||||
await authStore.initialize()
|
||||
}
|
||||
const isAuth = await authStore.validateAccess()
|
||||
if (isAuth) {
|
||||
if (to.meta.allowedRoles !== undefined) {
|
||||
|
||||
@@ -106,17 +106,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
})
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
if (isAuthenticated.value) {
|
||||
return null
|
||||
}
|
||||
const user = await manager.getUser()
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
return fetchUser()
|
||||
}
|
||||
|
||||
async function validateAccess() {
|
||||
const user = await manager.getUser()
|
||||
if (!user || user.expired) {
|
||||
@@ -124,6 +113,9 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
repository.defaults.headers.common.Authorization = `Bearer ${user.access_token}`
|
||||
repository.defaults.headers.post['Content-Type'] = 'application/json'
|
||||
if (!isAuthenticated.value) {
|
||||
await fetchUser()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -137,7 +129,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
async function completeLogin(redirectUrl) {
|
||||
try {
|
||||
const user = await manager.signinRedirectCallback()
|
||||
const user = await manager.signinCallback()
|
||||
isAuthenticated.value = true
|
||||
const previousPage = sessionStorage.getItem('previousPage')
|
||||
// Redirect the user to the previous page if available
|
||||
@@ -204,7 +196,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
addFidoCred,
|
||||
deleteFidoCreds,
|
||||
editFidoCred,
|
||||
initialize,
|
||||
login,
|
||||
$reset,
|
||||
updateAccount,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
import { useAuthStore } from '@/stores'
|
||||
import { useModoboaTheme } from '@/composables/theme'
|
||||
|
||||
@@ -10,10 +9,7 @@ const props = defineProps({
|
||||
const authStore = useAuthStore()
|
||||
const { enableTheme } = useModoboaTheme()
|
||||
|
||||
onMounted(() => {
|
||||
authStore.completeLogin(props.redirectUrl)
|
||||
})
|
||||
|
||||
await authStore.completeLogin(props.redirectUrl)
|
||||
await enableTheme()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -235,7 +235,6 @@ REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
|
||||
'rest_framework.authentication.TokenAuthentication',
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
),
|
||||
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
||||
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning',
|
||||
|
||||
@@ -252,7 +252,6 @@ REST_FRAMEWORK = {
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||
"oauth2_provider.contrib.rest_framework.OAuth2Authentication",
|
||||
"rest_framework.authentication.TokenAuthentication",
|
||||
"rest_framework.authentication.SessionAuthentication",
|
||||
),
|
||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.NamespaceVersioning",
|
||||
|
||||
Reference in New Issue
Block a user