0x0x230x

Untitled

Jul 23rd, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import {
  2. useIdentityToken,
  3. useLinkWithOAuth,
  4. useLoginWithOAuth,
  5. usePrivy,
  6. } from '@privy-io/expo';
  7. import { usePathname } from 'expo-router';
  8. import React from 'react';
  9. import { Alert, Text, TouchableOpacity } from 'react-native';
  10. import { PlatformIcon } from '../ui/PlatformIcon';
  11. import { useGenerateTokens } from '@/hooks/queries/useAuth';
  12.  
  13. export function SignInWithApple() {
  14. const linkWithOAuth = useLinkWithOAuth();
  15.  
  16. const pathname = usePathname();
  17. const { getAccessToken, user } = usePrivy();
  18. const { getIdentityToken } = useIdentityToken();
  19. const { mutate: generateTokens } = useGenerateTokens();
  20.  
  21. const handleSuccess = async () => {
  22. const [privyAccessToken, privyIdentityToken] = await Promise.all([
  23. getAccessToken(),
  24. getIdentityToken(),
  25. ]);
  26.  
  27. if (!privyAccessToken || !privyIdentityToken) {
  28. return null;
  29. }
  30.  
  31. generateTokens({
  32. accessToken: privyAccessToken,
  33. identityToken: privyIdentityToken,
  34. });
  35. };
  36.  
  37. const { login } = useLoginWithOAuth({
  38. onSuccess: handleSuccess,
  39. onError: (error) => {
  40. Alert.alert('Error', error.message);
  41. console.log('loginWithOAuth error', error);
  42. },
  43. });
  44.  
  45. return (
  46. <TouchableOpacity
  47. 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'
  48. onPress={() => {
  49. user
  50. ? linkWithOAuth.link({
  51. provider: 'apple',
  52. // isLegacyAppleIosBehaviorEnabled: false,
  53. redirectUri: pathname,
  54. })
  55. : login({
  56. provider: 'apple',
  57. // isLegacyAppleIosBehaviorEnabled: false,
  58. redirectUri: pathname,
  59. });
  60. }}
  61. activeOpacity={0.7}
  62. accessibilityRole='button'
  63. >
  64. <Text className='text-white text-2xl font-semibold font-superstar'>
  65. Sign in with Apple
  66. </Text>
  67. <PlatformIcon platform='apple' size={20} className='mr-2' />
  68. </TouchableOpacity>
  69. );
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment