Created
October 15, 2023 18:02
-
-
Save michaelkremenetsky/c98514c4388b2ec360d10ceba3fd92be to your computer and use it in GitHub Desktop.
Expo apple auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AppleAuthenticationScope, | |
signInAsync, | |
} from "expo-apple-authentication"; | |
import { | |
CryptoDigestAlgorithm, | |
digestStringAsync, | |
randomUUID, | |
} from "expo-crypto"; | |
/** | |
* Initiates the auth flow for the native Apple Sign In. | |
* Returns the token and nonce that will later be passed | |
* to Supabase to complete the sign in. | |
*/ | |
export async function initiateAppleSignIn() { | |
const rawNonce = randomUUID(); | |
const hashedNonce = await digestStringAsync( | |
CryptoDigestAlgorithm.SHA256, | |
rawNonce, | |
); | |
const credential = await signInAsync({ | |
requestedScopes: [ | |
AppleAuthenticationScope.FULL_NAME, | |
AppleAuthenticationScope.EMAIL, | |
], | |
nonce: hashedNonce, | |
}); | |
const token = credential.identityToken; | |
if (!token) throw new Error("No id token"); | |
return { token, nonce: rawNonce }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment