| 191 | } |
| 192 | |
| 193 | static async refreshToken(refresh) { |
| 194 | try { |
| 195 | return await request(`${host}/api/accounts/token/refresh/`, { |
| 196 | auth: false, |
| 197 | method: 'POST', |
| 198 | body: { refresh }, |
| 199 | }); |
| 200 | } catch (error) { |
| 201 | // If user does not exist or token is invalid, clear tokens |
| 202 | if (error.status === 401 || error.message?.includes('does not exist')) { |
| 203 | localStorage.removeItem('token'); |
| 204 | localStorage.removeItem('refreshToken'); |
| 205 | window.location.href = '/login'; // Redirect to login |
| 206 | } |
| 207 | throw error; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static async logout() { |
| 212 | return await request(`${host}/api/accounts/auth/logout/`, { |