mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
32 lines
629 B
TypeScript
32 lines
629 B
TypeScript
import http from '@/lib/http'
|
|
import {useUserStore} from '@/pinia'
|
|
|
|
const user = useUserStore()
|
|
const {login, logout} = user
|
|
|
|
const auth = {
|
|
async login(name: string, password: string) {
|
|
return http.post('/login', {
|
|
name: name,
|
|
password: password
|
|
}).then(r => {
|
|
login(r.token)
|
|
})
|
|
},
|
|
async casdoorLogin(code: string, state: string) {
|
|
await http.post('/casdoor_callback', {
|
|
code: code,
|
|
state: state
|
|
})
|
|
.then((r) => {
|
|
login(r.token)
|
|
})
|
|
},
|
|
logout() {
|
|
return http.delete('/logout').then(async () => {
|
|
logout()
|
|
})
|
|
}
|
|
}
|
|
|
|
export default auth
|