mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
优化登录 token 校验 (#345)
* 获得获取所有模型名称等功能 (#343) * 优化登录 token 校验 (#330) * fix manager-api bug * 优化登录注册流程,跑通注册登录、接口 * update package * 优化登录 token 校验: 1、后端新增 /api/v1/user/info 接口,优化 Oauth2Filter.getRequestToken 逻辑; 2、前端 /api/v1/user/login 登录成功后,保存 token 至浏览器本地; 3、前端请求添加本地 token。 --------- Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> * update:分离home页面的组件 --------- Co-authored-by: CGD <3030332422@qq.com> Co-authored-by: zhisheng <pzs034@gmail.com> Co-authored-by: hrz <1710360675@qq.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {goToPage, showDanger, showWarning} from '../utils/index'
|
||||
import {goToPage, showDanger, showWarning, isNotNull} from '../utils/index'
|
||||
import Constant from '../utils/constant'
|
||||
import Fly from 'flyio/dist/npm/fly';
|
||||
import store from '../store/index'
|
||||
|
||||
const fly = new Fly()
|
||||
// 设置超时
|
||||
@@ -25,7 +26,9 @@ function sendRequest() {
|
||||
_url: '',
|
||||
_responseType: undefined, // 新增响应类型字段
|
||||
'send'() {
|
||||
this._header.token = localStorage.getItem(Constant.STORAGE_KEY.TOKEN)
|
||||
if(isNotNull(store.getters.getToken)){
|
||||
this._header.Authorization = 'Bearer ' + (JSON.parse(store.getters.getToken)).token
|
||||
}
|
||||
|
||||
// 打印请求信息
|
||||
fly.request(this._url, this._data, {
|
||||
@@ -43,7 +46,7 @@ function sendRequest() {
|
||||
}
|
||||
}).catch((res) => {
|
||||
// 打印失败响应
|
||||
console.log(res)
|
||||
console.log('catch', res)
|
||||
httpHandlerError(res, this._failCallback)
|
||||
})
|
||||
return this
|
||||
@@ -97,6 +100,7 @@ function sendRequest() {
|
||||
*/
|
||||
// 在错误处理函数中添加日志
|
||||
function httpHandlerError(info, callBack) {
|
||||
console.log('httpHandlerError', info)
|
||||
|
||||
/** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */
|
||||
let networkError = false
|
||||
|
||||
Reference in New Issue
Block a user