feat: 实现飞书环境 token 过期自动刷新
- 当 API 返回 401 时,在飞书环境中自动调用免登刷新 token - 刷新成功后自动重试原始请求,用户无感知 - 飞书外环境仍跳转到登录页 - 防止死循环:请求只重试一次 - 登录页支持从 redirect 参数中提取 company 参数 流程: 1. API 返回 401 2. 飞书环境:调用 tt.requestAuthCode 获取新授权码 3. 用新授权码登录获取新 token 4. 用新 token 重试原始请求 5. 失败或非飞书环境:跳转登录页
This commit is contained in:
@@ -57,7 +57,24 @@ export default function Login() {
|
||||
const isInFeishu = ua.includes('Lark') || ua.includes('feishu') || ua.includes('lark')
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const authCode = urlParams.get('auth_code')
|
||||
const companyParam = urlParams.get('company')
|
||||
let companyParam = urlParams.get('company')
|
||||
|
||||
// 如果当前 URL 没有 company,尝试从 redirect 参数中提取
|
||||
// 这处理了 token 过期从其他页面跳转过来的场景
|
||||
if (!companyParam) {
|
||||
const redirect = urlParams.get('redirect')
|
||||
if (redirect) {
|
||||
try {
|
||||
const redirectUrl = new URL(redirect, window.location.origin)
|
||||
companyParam = redirectUrl.searchParams.get('company')
|
||||
console.log('🔍 从 redirect URL 中提取的 company 参数:', companyParam)
|
||||
} catch (e) {
|
||||
console.log('⚠️ 无法解析 redirect URL:', redirect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔍 最终使用的 company 参数:', companyParam)
|
||||
|
||||
// 如果 URL 中有授权码,直接处理登录
|
||||
if (authCode) {
|
||||
|
||||
Reference in New Issue
Block a user