- 用户登录成功,后端返回
access_token和refresh_token,前端存储。 - 前端每次 API 请求时,通过 Axios 请求拦截器自动在
Authorization头中添加Bearer access_token。 - 后端通过过滤器验证
access_token。 - 当
access_token过期,后端返回 401。 - 前端 Axios 响应拦截器捕获 401 错误。
- 拦截器发起
/auth/refresh请求,携带refresh_token。 - 后端验证
refresh_token,成功则返回新的access_token。 - 前端更新本地
access_token。 - 拦截器自动重试之前失败的请求(使用新
access_token)。 - 如果
refresh_token也失败或不存在,则清除本地 Token,跳转登录页。
-
Notifications
You must be signed in to change notification settings - Fork 0
Arata08/tokenDemo
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published