Skip to content

Commit

Permalink
hotfix: fix infinite loop on login with wrong credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
typeWolffo authored and k1eu committed Aug 7, 2024
1 parent f958efe commit 7820e04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 1 addition & 4 deletions examples/common_nestjs_remix/apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ import { StagingGuard } from "./common/guards/staging.guard";
return {
secret: configService.get<string>("jwt.secret")!,
signOptions: {
expiresIn: configService.get<string>(
"JWT_EXPIRATION_TIME",
"15min",
),
expiresIn: configService.get<string>("jwt.expirationTime"),
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class AuthService {
this.jwtService.signAsync(
{ userId, email },
{
expiresIn: "15m",
expiresIn: this.configService.get<string>("jwt.expirationTime"),
secret: this.configService.get<string>("jwt.secret"),
},
),
Expand Down
18 changes: 9 additions & 9 deletions examples/common_nestjs_remix/apps/web/app/api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ ApiClient.instance.interceptors.response.use(
(response) => response,
async (error) => {
const originalRequest = error.config;
const isLoggedIn = useAuthStore.getState().isLoggedIn;

if (!isLoggedIn) {
return Promise.reject(error);
}
const isLoginRequest = originalRequest.url.includes("/login");

if (error.response?.status === 401 && !originalRequest._retry) {
originalRequest._retry = true;

try {
await ApiClient.auth.authControllerRefreshTokens();
return ApiClient.instance(originalRequest);
} catch (error) {
return Promise.reject(error);
if (!isLoginRequest && useAuthStore.getState().isLoggedIn) {
try {
await ApiClient.auth.authControllerRefreshTokens();
return ApiClient.instance(originalRequest);
} catch (refreshError) {
useAuthStore.getState().setLoggedIn(false);
return Promise.reject(refreshError);
}
}
}

Expand Down

0 comments on commit 7820e04

Please sign in to comment.