Open satishaxtria opened 2 years ago
Almost the same. I get authenticated = false
every time, even on refresh success.
I also encountered it last few days. Not sure what is the issue, we're also using a persisting mechanism inside the app ( redux-persist ) and every time we close and open the app, it refreshes the session by opening and closing the inAppBrowser. Basically it should refresh only when the tokens expire, not every time the app opens.
@standreinmcp try this once
<ReactNativeKeycloakProvider autoRefreshToken authClient={keycloak} onTokens={tokens => { if (tokens?.token != 'undefined') { AsyncStorage.setItem('Tokens', JSON.stringify(tokens)) } }} initOptions={{ redirectUri: 'ur url', postLogoutRedirectUri: 'your url', inAppBrowserOptions: {}, }}>
useEffect(() => {
fetchData();
setTimeout(() => {
// navigation.navigate('HomeTabs');
navigation.navigate(keycloak?.authenticated ? 'HomeTabs' : 'AuthStack');
}, 100);
}, []);
i.e the screen which render as first Screen on DOM
const fetchData = async () => { let tokens = await AsyncStorage.getItem('Tokens'); let finalTokens = JSON.parse(tokens); // console.log('finalTokens', finalTokens); keycloak.init({ refreshToken: finalTokens?.refreshToken, token: finalTokens?.token, idToken: finalTokens?.idToken, redirectUri: 'your url', }); keycloak.onTokenExpired = () => { keycloak .updateToken(5) .then(() => { // console.log('onTokenExpired', 'token updated'); }) .catch(err => { console.log(err); }); }; };
Describe the bug
Adding KeycloakProvider
Login with keycloak
Accessing Keycloak Session --> Gives undefined token, idToken, refreshToken and authenticated = false
To Reproduce
Expected behavior Keycloak session should be accessible in any other functional component. Also it should be re initialised when App re launched. or there should be some persistent mechanism to store the session and retrieve when app re launched.
Screenshots NA
Smartphone
Additional context NA