This commit is contained in:
xd
2025-06-05 22:47:41 +08:00
parent ed99c7b1ae
commit 6805b590c7
17 changed files with 144 additions and 56 deletions

View File

@ -24,10 +24,10 @@ const clearToken = () => {
Taro.setStorageSync(TOKEN_EXPIRES_TIME, 0);
};
const requestToken = (): Promise<string> => {
const requestToken = (inviteCode?: string): Promise<string> => {
return getCode()
.then(code => {
return http.post<LoginResponse>(API.LOGIN, { data: { code } }).then(data => {
return http.post<LoginResponse>(API.LOGIN, { data: { code, inviteCode } }).then(data => {
const newToken = data?.token || '';
const expires = data?.expires || 0;
if (newToken) {
@ -47,12 +47,12 @@ const requestToken = (): Promise<string> => {
export const isTokenExpired = () => (Taro.getStorageSync(TOKEN_EXPIRES_TIME) || 0) < Date.now();
export const refreshToken = () => {
export const refreshToken = (inviteCode?: string) => {
if (_fetchTokenPromise) {
return _fetchTokenPromise;
}
clearToken();
_fetchTokenPromise = requestToken();
_fetchTokenPromise = requestToken(inviteCode);
return _fetchTokenPromise;
};