0x0x230x

Untitled

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