添加sso
This commit is contained in:
1 parent
fb812268d7
commit
6bee29a351
16 files changed
+917
-5
No files matched your search
+5
-1
@@ -15,7 +15,11 @@ http.interceptors.request.use((config) => {
|
||||
http.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401 && !error.config?.url?.endsWith('/auth/login')) {
|
||||
const isAuthenticationRequest =
|
||||
error.config?.url?.endsWith('/auth/login') ||
|
||||
error.config?.url?.endsWith('/auth/sso/exchange') ||
|
||||
error.config?.url?.endsWith('/auth/sso/bind')
|
||||
if (error.response?.status === 401 && !isAuthenticationRequest) {
|
||||
localStorage.removeItem('jiaowu_token')
|
||||
localStorage.removeItem('jiaowu_user')
|
||||
goLogin(location.pathname + location.search + location.hash)
|
||||
|
||||
@@ -13,6 +13,18 @@ const router = createRouter({
|
||||
component: () => import('../views/LoginView.vue'),
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: '/sso/callback',
|
||||
name: 'sso-callback',
|
||||
component: () => import('../views/SsoCallbackView.vue'),
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: '/sso/bind',
|
||||
name: 'sso-bind',
|
||||
component: () => import('../views/SsoBindView.vue'),
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: '/timetable',
|
||||
name: 'public-timetable',
|
||||
|
||||
+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,
|
||||
}
|
||||
})
|
||||
Loaded 3 of 16 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user