From 0b32d0d072012f372d6bda53a9b23efb09649573 Mon Sep 17 00:00:00 2001 From: WRadoslaw <92513933+WRadoslaw@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:20:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Hotfix=20for=20account=20creatio?= =?UTF-8?q?n=20(#4855)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add new error * Try to create session if its not present on request --- .../_auth/SignUpModal/SignUpModal.tsx | 19 +++++++++++++++++++ packages/atlas/src/hooks/useCreateMember.ts | 5 +++++ .../src/providers/auth/auth.provider.tsx | 9 --------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/atlas/src/components/_auth/SignUpModal/SignUpModal.tsx b/packages/atlas/src/components/_auth/SignUpModal/SignUpModal.tsx index fbf8651e5b..4271592367 100644 --- a/packages/atlas/src/components/_auth/SignUpModal/SignUpModal.tsx +++ b/packages/atlas/src/components/_auth/SignUpModal/SignUpModal.tsx @@ -11,6 +11,7 @@ import { AccountFormData, FaucetError, MemberFormData, RegisterError, useCreateM import { useMediaMatch } from '@/hooks/useMediaMatch' import { useSegmentAnalytics } from '@/hooks/useSegmentAnalytics' import { useUniqueMemberHandle } from '@/hooks/useUniqueMemberHandle' +import { handleAnonymousAuth } from '@/providers/auth/auth.helpers' import { useAuthStore } from '@/providers/auth/auth.store' import { useSnackbar } from '@/providers/snackbars' import { useYppStore } from '@/providers/ypp/ypp.store' @@ -59,9 +60,11 @@ export const SignUpModal = () => { const [amountOfTokens, setAmountofTokens] = useState() const memberRef = useRef(null) const memberPollingTries = useRef(0) + const haveTriedCreateSession = useRef(false) const ytResponseData = useYppStore((state) => state.ytResponseData) const setYppModalOpenName = useYppStore((state) => state.actions.setYppModalOpenName) const setYtResponseData = useYppStore((state) => state.actions.setYtResponseData) + const { anonymousUserId } = useAuthStore() const { displaySnackbar } = useSnackbar() const ytEmailIsValid = Boolean(ytResponseData?.email && !ytResponseData.email.includes('@pages.plusgoogle.com')) @@ -131,6 +134,21 @@ export const SignUpModal = () => { }) setAuthModalOpenName(undefined) } + if (error === RegisterError.SessionRequired) { + if (!haveTriedCreateSession.current) { + haveTriedCreateSession.current = true + handleAnonymousAuth(anonymousUserId).then(() => { + handleOrionAccountCreation() + }) + } else { + displaySnackbar({ + title: 'Something went wrong', + description: 'We could not create or find session. Please contact support.', + iconType: 'error', + }) + setAuthModalOpenName(undefined) + } + } }, onStart: () => { goToStep(SignUpSteps.Creating) @@ -148,6 +166,7 @@ export const SignUpModal = () => { }, }) }, [ + anonymousUserId, createNewOrionAccount, displaySnackbar, goToNextStep, diff --git a/packages/atlas/src/hooks/useCreateMember.ts b/packages/atlas/src/hooks/useCreateMember.ts index 58b21f4f46..82e5c26db2 100644 --- a/packages/atlas/src/hooks/useCreateMember.ts +++ b/packages/atlas/src/hooks/useCreateMember.ts @@ -70,6 +70,7 @@ export enum RegisterError { EmailAlreadyExists = 'EmailAlreadyExists', UnknownError = 'UnknownError', MembershipNotFound = 'MembershipNotFound', + SessionRequired = 'SessionRequired', } type SignUpParams = { @@ -241,9 +242,13 @@ export const useCreateMember = () => { 'To create new membership you need to use an email that is not connected to already existing account.', }) onError?.(RegisterError.EmailAlreadyExists) + return } else if (errorMessage.startsWith('Membership not found by id')) { onError?.(RegisterError.MembershipNotFound) return + } else if (errorMessage.startsWith("cookie 'session_id' required")) { + onError?.(RegisterError.SessionRequired) + return } else { displaySnackbar({ title: 'Something went wrong', diff --git a/packages/atlas/src/providers/auth/auth.provider.tsx b/packages/atlas/src/providers/auth/auth.provider.tsx index 4df318459e..82bd8c97a3 100644 --- a/packages/atlas/src/providers/auth/auth.provider.tsx +++ b/packages/atlas/src/providers/auth/auth.provider.tsx @@ -1,4 +1,3 @@ -import { useApolloClient } from '@apollo/client' import { u8aToHex } from '@polkadot/util' import { cryptoWaitReady } from '@polkadot/util-crypto' import { isAxiosError } from 'axios' @@ -39,7 +38,6 @@ export const AuthProvider: FC = ({ children }) => { const [lazyCurrentAccountQuery, { refetch }] = useGetCurrentAccountLazyQuery() const { setApiActiveAccount } = useJoystream() const { identifyUser, trackLogout } = useSegmentAnalytics() - const client = useApolloClient() const { anonymousUserId, encodedSeed, @@ -56,13 +54,6 @@ export const AuthProvider: FC = ({ children }) => { const { data } = await lazyCurrentAccountQuery() if (!data) { handleAnonymousAuth(anonymousUserId).then((userId) => { - client.refetchQueries({ - include: 'active', - onQueryUpdated: (observableQuery) => { - // don't refetch GetBasicVideos query, as it's a duplicate of GetBasicVideosLightweight - return observableQuery.queryName !== 'GetBasicVideos' - }, - }) setAnonymousUserId(userId ?? null) }) setIsAuthenticating(false)