Migrate auth flow module to pinia store
This commit is contained in:
parent
60e5c3b042
commit
4ee26c6041
8 changed files with 91 additions and 110 deletions
|
|
@ -1,86 +0,0 @@
|
|||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
|
||||
const PASSWORD_STRATEGY = 'password'
|
||||
const TOKEN_STRATEGY = 'token'
|
||||
|
||||
// MFA strategies
|
||||
const TOTP_STRATEGY = 'totp'
|
||||
const RECOVERY_STRATEGY = 'recovery'
|
||||
|
||||
// initial state
|
||||
const state = {
|
||||
settings: {},
|
||||
strategy: PASSWORD_STRATEGY,
|
||||
initStrategy: PASSWORD_STRATEGY // default strategy from config
|
||||
}
|
||||
|
||||
const resetState = (state) => {
|
||||
state.strategy = state.initStrategy
|
||||
state.settings = {}
|
||||
}
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
settings: (state) => {
|
||||
return state.settings
|
||||
},
|
||||
requiredPassword: (state) => {
|
||||
return state.strategy === PASSWORD_STRATEGY
|
||||
},
|
||||
requiredToken: (state) => {
|
||||
return state.strategy === TOKEN_STRATEGY
|
||||
},
|
||||
requiredTOTP: (state) => {
|
||||
return state.strategy === TOTP_STRATEGY
|
||||
},
|
||||
requiredRecovery: (state) => {
|
||||
return state.strategy === RECOVERY_STRATEGY
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setInitialStrategy (state, strategy) {
|
||||
if (strategy) {
|
||||
state.initStrategy = strategy
|
||||
state.strategy = strategy
|
||||
}
|
||||
},
|
||||
requirePassword (state) {
|
||||
state.strategy = PASSWORD_STRATEGY
|
||||
},
|
||||
requireToken (state) {
|
||||
state.strategy = TOKEN_STRATEGY
|
||||
},
|
||||
requireMFA (state, { settings }) {
|
||||
state.settings = settings
|
||||
state.strategy = TOTP_STRATEGY // default strategy of MFA
|
||||
},
|
||||
requireRecovery (state) {
|
||||
state.strategy = RECOVERY_STRATEGY
|
||||
},
|
||||
requireTOTP (state) {
|
||||
state.strategy = TOTP_STRATEGY
|
||||
},
|
||||
abortMFA (state) {
|
||||
resetState(state)
|
||||
}
|
||||
}
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
|
||||
async login ({ state, dispatch }, { access_token: accessToken }) {
|
||||
useOAuthStore().setToken(accessToken)
|
||||
await dispatch('loginUser', accessToken, { root: true })
|
||||
resetState(state)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import api from './api.js'
|
|||
import config from './config.js'
|
||||
import profileConfig from './profileConfig.js'
|
||||
import adminSettings from './adminSettings.js'
|
||||
import authFlow from './auth_flow.js'
|
||||
import drafts from './drafts.js'
|
||||
import chats from './chats.js'
|
||||
|
||||
|
|
@ -19,7 +18,6 @@ export default {
|
|||
config,
|
||||
profileConfig,
|
||||
adminSettings,
|
||||
authFlow,
|
||||
drafts,
|
||||
chats
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue