| 118 | } |
| 119 | |
| 120 | function storeAuthSession(loginData) { |
| 121 | if (!loginData?.access_token) { |
| 122 | throw new Error('SUB2API 登录返回缺少 access_token。'); |
| 123 | } |
| 124 | |
| 125 | localStorage.setItem('auth_token', loginData.access_token); |
| 126 | if (loginData.refresh_token) { |
| 127 | localStorage.setItem('refresh_token', loginData.refresh_token); |
| 128 | } else { |
| 129 | localStorage.removeItem('refresh_token'); |
| 130 | } |
| 131 | if (loginData.expires_in) { |
| 132 | localStorage.setItem('token_expires_at', String(Date.now() + Number(loginData.expires_in) * 1000)); |
| 133 | } |
| 134 | if (loginData.user) { |
| 135 | localStorage.setItem('auth_user', JSON.stringify(loginData.user)); |
| 136 | } |
| 137 | sessionStorage.removeItem('auth_expired'); |
| 138 | } |
| 139 | |
| 140 | async function loginSub2Api(payload = {}) { |
| 141 | const email = (payload.sub2apiEmail || '').trim(); |