Skip to content

Commit

Permalink
remove unnecessary, add changes good for logout
Browse files Browse the repository at this point in the history
  • Loading branch information
dudiiiiiiii committed Oct 15, 2024
1 parent 698a648 commit 3d843b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/services/AuthService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ const Auth = ({ children }: GenericContextProviderProps) => {
);
};

if (!initialized || !keycloak.authenticated) return;

if (keycloak.isTokenExpired()) {
logout();
if (!initialized || !keycloak.authenticated) {
if (initialized && !keycloak.authenticated) {
logout();
}

return;
}
Expand Down Expand Up @@ -290,8 +290,7 @@ const Auth = ({ children }: GenericContextProviderProps) => {
);

const tokenRefresh = useCallback(() => {
if (!initialized || !keycloak.authenticated || user?.source != 'keycloak')
return Promise.resolve();
if (!initialized || user?.source != 'keycloak') return Promise.resolve();

return keycloak
.updateToken(300) // 5 minutes in seconds minimum remaining lifetime for token before refresh is allowed
Expand All @@ -302,9 +301,7 @@ const Auth = ({ children }: GenericContextProviderProps) => {
{ variant: 'success' }
);
})
.catch(reason => {
logout();
});
.catch(reason => {});
}, [initialized, user?.source, keycloak, enqueueSnackbar]);

useIntervalAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/services/KeycloakAuthService.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Keycloak, { KeycloakInitOptions } from 'keycloak-js';
import { KeycloakProvider, useKeycloak } from 'keycloak-react-web';
import { ReactNode, useCallback, useEffect } from 'react';
import { ReactNode, useCallback } from 'react';

import { useConfig } from '../config/ConfigService';
import { createSubstituteContext, GenericContextProviderProps } from './GenericContext';
Expand Down

0 comments on commit 3d843b2

Please sign in to comment.