forked from trevorpfiz/create-t3-turbo-supabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
35 lines (31 loc) · 832 Bytes
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 };
}