feat: implement authentication flow with JWT refresh logic, Login page, and user session management

This commit is contained in:
Your Name
2026-04-10 19:24:15 +05:30
parent c4733249fa
commit 7748cd10c9
7 changed files with 205 additions and 30 deletions
+13 -5
View File
@@ -13,15 +13,23 @@ authApiClient.interceptors.response.use(
(response) => response,
async (error: AxiosError) => {
if (
error.response.status === 401 &&
!error.config.url?.includes("refresh/")
error.response?.status === 401 &&
!error.config?.url?.includes("refresh/")
) {
// token expired, refresh it
try {
const response = await authApiClient.post("refresh/");
if (response.status === 200) {
// refresh successful, retry the request
return authApiClient(error.config);
const newAccessToken = response.data.access;
// update the auth store so the retry uses the new token
useAuth.setState({
accessToken: newAccessToken,
isAuthenticated: true,
});
if (error.config) {
error.config.headers.Authorization = `Bearer ${newAccessToken}`;
return authApiClient(error.config);
}
}
} catch (error) {
return Promise.reject(error);