优化
This commit is contained in:
+10
-1
@@ -1,11 +1,13 @@
|
||||
import { API_ROOT } from '@/config/runtime.js'
|
||||
|
||||
function authRequest(path, data) {
|
||||
function authRequest(path, data, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${API_ROOT}${path}`,
|
||||
method: 'POST',
|
||||
data,
|
||||
header: options.header,
|
||||
timeout: options.timeout || 15000,
|
||||
success(response) {
|
||||
const body = response.data || {}
|
||||
if (String(body.code ?? response.statusCode) !== '200') {
|
||||
@@ -34,3 +36,10 @@ export function login(username, password) {
|
||||
export function refresh(refreshToken) {
|
||||
return authRequest('/auth/refresh', { refreshToken })
|
||||
}
|
||||
|
||||
export function logout(refreshToken, accessToken) {
|
||||
return authRequest('/auth/logout', { refreshToken }, {
|
||||
header: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
|
||||
timeout: 5000
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user