refactor(frontend): merge authserver web login
This commit is contained in:
+23
-1
@@ -3,7 +3,29 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 根组件
|
||||
import { onMounted } from 'vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { getToken, removeToken } from '@/utils/auth'
|
||||
import { redirectToSSO } from '@/utils/sso'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
onMounted(async () => {
|
||||
const token = getToken()
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await authApi.getUserInfo()
|
||||
authStore.setAuth(token, data)
|
||||
} catch {
|
||||
authStore.clearAuth()
|
||||
removeToken()
|
||||
redirectToSSO()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user