Skip to content

Commit

Permalink
🔥 Hotfix for account creation (#4855)
Browse files Browse the repository at this point in the history
* Add new error

* Try to create session if its not present on request
  • Loading branch information
WRadoslaw authored Sep 13, 2023
1 parent 27e0c17 commit 0b32d0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
19 changes: 19 additions & 0 deletions packages/atlas/src/components/_auth/SignUpModal/SignUpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -59,9 +60,11 @@ export const SignUpModal = () => {
const [amountOfTokens, setAmountofTokens] = useState<number>()
const memberRef = useRef<string | null>(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'))

Expand Down Expand Up @@ -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)
Expand All @@ -148,6 +166,7 @@ export const SignUpModal = () => {
},
})
}, [
anonymousUserId,
createNewOrionAccount,
displaySnackbar,
goToNextStep,
Expand Down
5 changes: 5 additions & 0 deletions packages/atlas/src/hooks/useCreateMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export enum RegisterError {
EmailAlreadyExists = 'EmailAlreadyExists',
UnknownError = 'UnknownError',
MembershipNotFound = 'MembershipNotFound',
SessionRequired = 'SessionRequired',
}

type SignUpParams<T, E> = {
Expand Down Expand Up @@ -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',
Expand Down
9 changes: 0 additions & 9 deletions packages/atlas/src/providers/auth/auth.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useApolloClient } from '@apollo/client'
import { u8aToHex } from '@polkadot/util'
import { cryptoWaitReady } from '@polkadot/util-crypto'
import { isAxiosError } from 'axios'
Expand Down Expand Up @@ -39,7 +38,6 @@ export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
const [lazyCurrentAccountQuery, { refetch }] = useGetCurrentAccountLazyQuery()
const { setApiActiveAccount } = useJoystream()
const { identifyUser, trackLogout } = useSegmentAnalytics()
const client = useApolloClient()
const {
anonymousUserId,
encodedSeed,
Expand All @@ -56,13 +54,6 @@ export const AuthProvider: FC<PropsWithChildren> = ({ 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)
Expand Down

0 comments on commit 0b32d0d

Please sign in to comment.