check sessions state as well

Signed-off-by: Vladimir Masarik <vladimir.masarik@ef.com>
This commit is contained in:
Vladimir Masarik
2022-09-02 14:00:38 +02:00
parent 4ce0c846cc
commit 5e00eb69c5
@@ -26,6 +26,7 @@ import {
import {
ApiRef,
SessionApi,
SessionState,
ProfileInfoApi,
ProfileInfo,
useApi,
@@ -48,16 +49,22 @@ export const ProviderSettingsItem = (props: {
useEffect(() => {
let didCancel = false;
const subscription = api.sessionState$().subscribe(() => {
if (!didCancel) {
api
.getProfile({ optional: true })
.then((profile: ProfileInfo | undefined) => {
setSignedIn(profile !== undefined);
setProfileEmail(profile?.email ?? '');
});
}
});
const subscription = api
.sessionState$()
.subscribe((sessionState: SessionState) => {
if (!didCancel) {
api
.getProfile({ optional: true })
.then((profile: ProfileInfo | undefined) => {
if (sessionState === SessionState.SignedIn) {
setSignedIn(true);
} else {
setSignedIn(profile !== undefined);
}
setProfileEmail(profile?.email ?? '');
});
}
});
return () => {
didCancel = true;