Management API Reference

Native Login With Apple

React Native Apple Login

When working with Expo, you can use the Expo AppleAuthentication library to obtain an ID token that you can pass to openfort-js authenticateThirdParty method.

Make sure you have configured your iOs credentials in the Openfort dashboard. Follow the configuration steps.

Follow the Expo docs for installation and configuration instructions. See the openfort-js reference for instructions on initializing the openfort-js client in React Native.

./components/Auth.native.tsx

_46
import { Platform } from 'react-native'
_46
import * as AppleAuthentication from 'expo-apple-authentication'
_46
// the initialized instance of openfort-js client
_46
import { openfort } from '../utils/openfort'
_46
_46
export function Auth() {
_46
return (
_46
<AppleAuthentication.AppleAuthenticationButton
_46
buttonType={AppleAuthentication.AppleAuthenticationButtonType.SIGN_IN}
_46
buttonStyle={AppleAuthentication.AppleAuthenticationButtonStyle.BLACK}
_46
cornerRadius={5}
_46
style={{ width: 200, height: 64 }}
_46
onPress={async () => {
_46
try {
_46
const credential = await AppleAuthentication.signInAsync({
_46
requestedScopes: [
_46
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
_46
AppleAuthentication.AppleAuthenticationScope.EMAIL,
_46
],
_46
})
_46
// Sign in via Openfort Auth.
_46
if (credential.identityToken) {
_46
const {
_46
error,
_46
data: { user },
_46
} = await openfort.loginWithIdToken({
_46
provider: OAuthProvider.APPLE,
_46
token: credential.identityToken,
_46
})
_46
console.log(JSON.stringify({ error, user }, null, 2))
_46
if (!error) {
_46
// User is signed in.
_46
}
_46
} else {
_46
throw new Error('No identityToken.')
_46
}
_46
} catch (e) {
_46
if (e.code === 'ERR_REQUEST_CANCELED') {
_46
// handle that the user cancelled the sign-in flow
_46
} else {
_46
// handle other errors
_46
}
_46
}
_46
}}
_46
/>
_46
}

When working with bare React Native, you can use invertase/react-native-apple-authentication to obtain the ID token.