From 9b3c6083f9b06e3430dfb739e4ffea53ec2ee744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E7=A7=8B=E6=97=AD?= Date: Wed, 22 Feb 2023 17:04:59 +0800 Subject: [PATCH] =?UTF-8?q?refreshToken=E6=93=8D=E4=BD=9C=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 5517a8e..57a975c 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,4 +1,5 @@ import axios from '@/utils/axios' +import { type AxiosResponse } from 'axios' export interface LoginInputDto { email: string @@ -28,6 +29,13 @@ export async function login(data: LoginInputDto) { return axios.post('/api/auth/login', data) } +let refreshing: Promise> | null + export async function refreshToken(data: TokenRefreshPayload) { - return axios.put('/api/auth/token', data) + if (!refreshing) { + refreshing = axios.put('/api/auth/token', data).finally(() => { + refreshing = null + }) + } + return refreshing }