Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求锁功能 #118

Open
RamirezET opened this issue Jun 28, 2023 · 1 comment
Open

请求锁功能 #118

RamirezET opened this issue Jun 28, 2023 · 1 comment

Comments

@RamirezET
Copy link

例如某个页面要请求多个接口,接口均需要token,此时token不存在或过期,这多个请求就会一起去请求token,能否提供一个功能类似是这样,请求前锁定,验证token有效或者无效了拿回真正token后,unlock同时发出的请求继续执行,这样就不会同时去请求token

request.interceptors.request.use((config) => {
	return new Promise((resolve, reject) => {
		// console.log("请求拦截器");
		request.lock()
		getAccessToken()
			.then((data) => {
				const {
					tokenType,
					value
				} = data
				config.headers['Authorization'] = tokenType + ' ' + value
				resolve(config)
				request.unlock()
			})
			.catch((error) => {
				request.unlock()
				reject(error)
			})
	})
})

当然也可以在每个请求resolve之后再执行下一个请求,但不那么优雅

谢谢大佬

@lei-mu
Copy link
Owner

lei-mu commented Jun 28, 2023

这个事,现在是有解决方案的。就是无痛刷新token.
只不过没有集成到插件里,看后期能不能弄进去吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants