-
Notifications
You must be signed in to change notification settings - Fork 2
/
apple.tsx
33 lines (28 loc) · 1013 Bytes
/
apple.tsx
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
import React, { ReactNode } from 'react'
import { TouchableOpacity, Image, Platform } from 'react-native'
import * as AppleAuthentication from 'expo-apple-authentication'
const appleLogo = require('./assets/images/apple.png')
export type AppleAuthProps = {
customButton?: ReactNode
onSuccess: (token: string) => void
onError: (error: string) => void
}
const AppleAuth = ({ onSuccess, onError, customButton }: AppleAuthProps) => {
const isAndroid = Platform.OS === 'android'
const appleAuth = async () => {
try {
const { identityToken } = await AppleAuthentication.signInAsync({
requestedScopes: [AppleAuthentication.AppleAuthenticationScope.EMAIL]
})
return onSuccess(identityToken as string)
} catch (e: any) {
return onError(e.message)
}
}
return (
<TouchableOpacity onPress={appleAuth}>
{customButton ? customButton : <Image source={appleLogo} style={{ height: 50, width: 50 }} />}
</TouchableOpacity>
)
}
export default AppleAuth