Skip to content

Commit a1c9864

Browse files
committed
Handle sigin response for success
1 parent 23660e2 commit a1c9864

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/services/auth.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { appleAuth, AppleRequestResponse } from '@invertase/react-native-apple-a
33
import { stateTree } from 'models';
44
import { KeychainStorage } from 'services/storage';
55
import { signinEMRPatient } from 'services/emr';
6-
import { mapFailure, mapSuccess } from 'fhir-react/src/services/service';
6+
import { isSuccess } from 'fhir-react/src/libs/remoteData';
77

88
const AUTH_IDENTITY_KEYCHAIN_PATH = 'apple_identity';
99

@@ -46,21 +46,21 @@ export async function signin(authenticated: AuthenticatedAppleResponse) {
4646
}
4747
await KeychainStorage.store(AUTH_IDENTITY_KEYCHAIN_PATH, identity);
4848

49-
mapSuccess(
50-
await signinEMRPatient(authenticated.jwt, {
51-
name: {
52-
given: authenticated.username?.givenName ?? undefined,
53-
family: authenticated.username?.familyName ?? undefined,
54-
},
55-
}),
56-
(patient) => stateTree.user.switchPatient(patient),
57-
);
49+
return await signinEMRPatient(authenticated.jwt, {
50+
name: {
51+
given: authenticated.username?.givenName ?? undefined,
52+
family: authenticated.username?.familyName ?? undefined,
53+
},
54+
});
5855
}
5956

6057
export async function signinWithApple() {
6158
const authentication = await openAppleAuthenticationDialog();
6259
if (authentication.status === AuthStatus.Authenticated) {
63-
signin(authentication);
60+
const response = await signin(authentication);
61+
if (isSuccess(response)) {
62+
stateTree.user.switchPatient(response.data);
63+
}
6464
}
6565
return authentication;
6666
}

0 commit comments

Comments
 (0)