perf: token

This commit is contained in:
archer
2023-08-05 11:32:43 +08:00
parent eb5a252654
commit 761ae74b0a
13 changed files with 69 additions and 45 deletions

View File

@@ -3,6 +3,7 @@ import { getErrText } from '@/utils/tools';
import { parseStreamChunk, SSEParseData } from '@/utils/sse';
import type { ChatHistoryItemResType } from '@/types/chat';
import { StartChatFnProps } from '@/components/ChatBox';
import { getToken } from '@/utils/user';
interface StreamFetchProps {
url?: string;
@@ -24,7 +25,8 @@ export const streamFetch = ({
const response = await window.fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
token: getToken()
},
signal: abortSignal.signal,
body: JSON.stringify({

View File

@@ -1,5 +1,5 @@
import axios, { Method, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { clearCookie } from '@/utils/user';
import { clearToken, getToken } from '@/utils/user';
import { TOKEN_ERROR_CODE } from '@/service/errorCode';
interface ConfigType {
@@ -18,7 +18,7 @@ interface ResponseDataType {
*/
function requestStart(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig {
if (config.headers) {
// config.headers.Authorization = getToken();
config.headers.token = getToken();
}
return config;
@@ -57,7 +57,7 @@ function responseError(err: any) {
}
// 有报错响应
if (err?.code in TOKEN_ERROR_CODE) {
clearCookie();
clearToken();
window.location.replace(
`/login?lastRoute=${encodeURIComponent(location.pathname + location.search)}`
);

View File

@@ -2,6 +2,7 @@ import type { UserType } from '@/types/user';
import type { PromotionRecordSchema } from '@/types/mongoSchema';
export interface ResLogin {
user: UserType;
token: string;
}
export interface PromotionRecordType {