添加sso
This commit is contained in:
+29
-1
@@ -27,6 +27,24 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
async function exchangeSso(code: string) {
|
||||
const { data } = await http.post('/auth/sso/exchange', { code })
|
||||
token.value = data.token
|
||||
user.value = data.user
|
||||
localStorage.setItem('jiaowu_token', data.token)
|
||||
localStorage.setItem('jiaowu_user', JSON.stringify(data.user))
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
async function bindSso(code: string, userName: string, password: string) {
|
||||
const { data } = await http.post('/auth/sso/bind', { code, userName, password })
|
||||
token.value = data.token
|
||||
user.value = data.user
|
||||
localStorage.setItem('jiaowu_token', data.token)
|
||||
localStorage.setItem('jiaowu_user', JSON.stringify(data.user))
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (!token.value) return
|
||||
const { data } = await http.get('/auth/me')
|
||||
@@ -42,5 +60,15 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
return { token, user, isLoggedIn, isSuperAdmin, login, refresh, logout }
|
||||
return {
|
||||
token,
|
||||
user,
|
||||
isLoggedIn,
|
||||
isSuperAdmin,
|
||||
login,
|
||||
exchangeSso,
|
||||
bindSso,
|
||||
refresh,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user