Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { STATIC_IMAGES_URL } from "@hey/data/constants";
2import { ERRORS } from "@hey/data/errors";
3import { useSwitchAccountMutation } from "@hey/indexer";
4import type { ApolloClientError } from "@hey/types/errors";
5import { useCallback, useEffect } from "react";
6import { H4, Image } from "@/components/Shared/UI";
7import errorToast from "@/helpers/errorToast";
8import reloadAllTabs from "@/helpers/reloadAllTabs";
9import { signIn } from "@/store/persisted/useAuthStore";
10import { useSignupStore } from ".";
11
12const Success = () => {
13 const { accountAddress, onboardingToken } = useSignupStore();
14
15 const onError = useCallback((error: ApolloClientError) => {
16 errorToast(error);
17 }, []);
18
19 const [switchAccount] = useSwitchAccountMutation({ onError });
20
21 const handleAuth = async () => {
22 try {
23 const auth = await switchAccount({
24 context: { headers: { "X-Access-Token": onboardingToken } },
25 variables: { request: { account: accountAddress } }
26 });
27
28 if (auth.data?.switchAccount.__typename === "AuthenticationTokens") {
29 const accessToken = auth.data?.switchAccount.accessToken;
30 const refreshToken = auth.data?.switchAccount.refreshToken;
31 signIn({ accessToken, refreshToken });
32 reloadAllTabs();
33 return;
34 }
35
36 return onError({ message: ERRORS.SomethingWentWrong });
37 } catch {
38 onError({ message: ERRORS.SomethingWentWrong });
39 }
40 };
41
42 useEffect(() => {
43 handleAuth();
44 }, []);
45
46 return (
47 <div className="m-8 flex flex-col items-center justify-center">
48 <H4>Waaa-hey! You got your account!</H4>
49 <div className="mt-3 text-center font-semibold text-gray-500 dark:text-gray-200">
50 Welcome to decentralised social where everything is sooooooooooooo much
51 better! 馃帀
52 </div>
53 <Image
54 alt="Dizzy emoji"
55 className="mx-auto mt-8 size-14"
56 height={56}
57 src={`${STATIC_IMAGES_URL}/emojis/dizzy.png`}
58 width={56}
59 />
60 <i className="mt-8 text-gray-500 dark:text-gray-200">
61 We are taking you to Hey...
62 </i>
63 </div>
64 );
65};
66
67export default Success;