Skip to content

Instantly share code, notes, and snippets.

@michaelkremenetsky
Created October 15, 2023 18:02
Show Gist options
  • Save michaelkremenetsky/c98514c4388b2ec360d10ceba3fd92be to your computer and use it in GitHub Desktop.
Save michaelkremenetsky/c98514c4388b2ec360d10ceba3fd92be to your computer and use it in GitHub Desktop.
Expo apple auth
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