* 清除所有认证凭证
()
| 140 | * 清除所有认证凭证 |
| 141 | */ |
| 142 | function clearAuthCredentials() { |
| 143 | if (typeof window === 'undefined') return; |
| 144 | |
| 145 | // 清除 localStorage |
| 146 | localStorage.removeItem('access_token'); |
| 147 | localStorage.removeItem('refresh_token'); |
| 148 | localStorage.removeItem('token_expires_at'); |
| 149 | localStorage.removeItem('user'); |
| 150 | |
| 151 | // 清除 cookies(设置过期时间为过去) |
| 152 | if (typeof document !== 'undefined') { |
| 153 | document.cookie = 'access_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; |
| 154 | document.cookie = 'refresh_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; |
| 155 | document.cookie = 'user=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; |
| 156 | console.log('[clearAuthCredentials] 已清除所有认证凭证(localStorage + cookies)'); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * 刷新 Token |
no outgoing calls
no test coverage detected