Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- useIdentityToken,
- useLinkWithOAuth,
- useLoginWithOAuth,
- usePrivy,
- } from '@privy-io/expo';
- import { usePathname } from 'expo-router';
- import React from 'react';
- import { Alert, Text, TouchableOpacity } from 'react-native';
- import { PlatformIcon } from '../ui/PlatformIcon';
- import { useGenerateTokens } from '@/hooks/queries/useAuth';
- export function SignInWithApple() {
- const linkWithOAuth = useLinkWithOAuth();
- const pathname = usePathname();
- const { getAccessToken, user } = usePrivy();
- const { getIdentityToken } = useIdentityToken();
- const { mutate: generateTokens } = useGenerateTokens();
- const handleSuccess = async () => {
- const [privyAccessToken, privyIdentityToken] = await Promise.all([
- getAccessToken(),
- getIdentityToken(),
- ]);
- if (!privyAccessToken || !privyIdentityToken) {
- return null;
- }
- generateTokens({
- accessToken: privyAccessToken,
- identityToken: privyIdentityToken,
- });
- };
- const { login } = useLoginWithOAuth({
- onSuccess: handleSuccess,
- onError: (error) => {
- Alert.alert('Error', error.message);
- console.log('loginWithOAuth error', error);
- },
- });
- return (
- <TouchableOpacity
- className='flex-row items-center justify-center w-full bg-[#222224] hover:bg-[#222224]/70 transition-all mx-0.5 text-gray-300 hover:text-white border border-[#2c2c2e] py-2 px-5 rounded-lg gap-2'
- onPress={() => {
- user
- ? linkWithOAuth.link({
- provider: 'apple',
- // isLegacyAppleIosBehaviorEnabled: false,
- redirectUri: pathname,
- })
- : login({
- provider: 'apple',
- // isLegacyAppleIosBehaviorEnabled: false,
- redirectUri: pathname,
- });
- }}
- activeOpacity={0.7}
- accessibilityRole='button'
- >
- <Text className='text-white text-2xl font-semibold font-superstar'>
- Sign in with Apple
- </Text>
- <PlatformIcon platform='apple' size={20} className='mr-2' />
- </TouchableOpacity>
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment