0x0x230x

Untitled

Nov 20th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. import { Button } from '@/components/ui/button';
  2. import { Label } from '@/components/ui/label';
  3. import Image from 'next/image';
  4. import {
  5. SignInButton,
  6. SignedIn,
  7. SignedOut,
  8. useClerk,
  9. useUser,
  10. } from '@clerk/nextjs';
  11. import { useEffect, useState } from 'react';
  12. import { useAsyncEffect } from '@/lib/hooks/useAsyncEffect';
  13. import { env } from '@/lib/config/env';
  14. import { ClipLoader } from 'react-spinners';
  15. import { usePostHog } from 'posthog-js/react';
  16. import {
  17. isClerkAPIResponseError,
  18. isEmailLinkError,
  19. } from '@clerk/nextjs/errors';
  20.  
  21. export default function SelectSocialLogin({
  22. onNext,
  23. }: {
  24. onNext: (hasFid: boolean) => void;
  25. }) {
  26. const { isSignedIn, user } = useUser();
  27. const [isLoading, setIsLoading] = useState(false);
  28. const postHog = usePostHog();
  29.  
  30. useEffect(() => {
  31. postHog.capture('ext_onboard_10');
  32. }, []);
  33.  
  34. useAsyncEffect(async () => {
  35. if (!isSignedIn) {
  36. return;
  37. }
  38.  
  39. setIsLoading(true);
  40.  
  41. const body = JSON.stringify({
  42. social_login: 'twitter',
  43. username: user.username,
  44. email: user.emailAddresses[0].emailAddress,
  45. pfp_url: user.imageUrl,
  46. display_name: user.firstName,
  47. clerk_user_id: user.id,
  48. });
  49.  
  50. const url = new URL(`${env.NEXT_PUBLIC_APP_BASE_URL}/auth/register`);
  51.  
  52. const options = {
  53. method: 'POST',
  54. headers: {
  55. 'Content-Type': 'application/json',
  56. },
  57. body,
  58. };
  59.  
  60. try {
  61. const response = await fetch(url, options);
  62.  
  63. if (!response.ok) {
  64. setIsLoading(false);
  65. onNext(false);
  66. return;
  67. }
  68.  
  69. const data = await response.json();
  70. const fid = data.data.fid;
  71.  
  72. setIsLoading(false);
  73. onNext(fid !== null);
  74. } catch (error) {
  75. setIsLoading(false);
  76. onNext(false);
  77. }
  78. }, [isSignedIn, user]);
  79.  
  80. return (
  81. <div className="flex flex-col items-center bg-[#2f2f2f] rounded-lg w-[488px] py-10 gap-10 px-4">
  82. <Label className="text-[#c4c8cc] text-[28px] font-normal leading-9 uppercase text-center">
  83. Connect your X and Farcaster Accounts to get started
  84. </Label>
  85. <SignedOut>
  86. <SignInButton>
  87. <Button
  88. disabled={isLoading}
  89. className="bg-[#3A3A3A] hover:bg-[#3A3A3A]/20 rounded-[14.45px] border-2 border-[#434343] py-6 w-[380px]"
  90. >
  91. {isLoading ? (
  92. <div className="flex items-center justify-center gap-2">
  93. <ClipLoader color="#fff" size={15} />
  94. <Label className="leading-9 tracking-tight text-lg">
  95. SIGNING IN...
  96. </Label>
  97. </div>
  98. ) : (
  99. <>
  100. <Image
  101. src="/twitter-icon.svg"
  102. alt="twitter-icon"
  103. className="size-5 mr-2"
  104. width={0}
  105. height={0}
  106. />
  107. <Label className="leading-9 tracking-tight text-lg cursor-pointer">
  108. SIGN INTO X
  109. </Label>
  110. </>
  111. )}
  112. </Button>
  113. </SignInButton>
  114. </SignedOut>
  115. <SignedIn>
  116. <Button
  117. disabled={true}
  118. className="bg-[#3A3A3A] hover:bg-[#3A3A3A]/20 rounded-[14.45px] border-2 border-[#434343] py-6 w-[380px]"
  119. >
  120. <div className="flex items-center justify-center gap-2">
  121. <ClipLoader color="#fff" size={15} />
  122. <Label className="leading-9 tracking-tight text-lg">
  123. SIGNING IN...
  124. </Label>
  125. </div>
  126. </Button>
  127. </SignedIn>
  128. </div>
  129. );
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment