Skip to content

Commit

Permalink
fix: google signup / singin on cancel improvement (artsy#10084)
Browse files Browse the repository at this point in the history
fix: do not throw error / show message when user cancels sign in / up with google
  • Loading branch information
gkartalis authored Apr 16, 2024
1 parent b0a3a4a commit 8ff8368
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
31 changes: 19 additions & 12 deletions src/app/Scenes/Onboarding/OnboardingSocialPick.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EnvelopeIcon, Spacer, Flex, Text, Join, Button, LegacyScreen } from "@artsy/palette-mobile"
import { statusCodes } from "@react-native-google-signin/google-signin"
import { NavigationProp, useNavigation } from "@react-navigation/native"
import { captureMessage } from "@sentry/react-native"
import LoadingModal from "app/Components/Modals/LoadingModal"
Expand Down Expand Up @@ -51,6 +52,7 @@ export const OnboardingSocialPick: React.FC<OnboardingSocialPickProps> = ({ mode
oauthToken,
idToken,
appleUid,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
} = meta!
const navParams: Omit<
OnboardingNavigationStack["OnboardingSocialLink"],
Expand Down Expand Up @@ -86,20 +88,25 @@ export const OnboardingSocialPick: React.FC<OnboardingSocialPickProps> = ({ mode
}

const handleError = (error: AuthPromiseRejectType) => {
captureMessage("AUTH_FAILURE: " + error.message)

const canBeLinked =
error.error === "User Already Exists" && error.meta && error.meta.existingProviders
if (canBeLinked) {
handleErrorWithAlternativeProviders(error.meta)
if (error.message === statusCodes.SIGN_IN_CANCELLED) {
return
}
GlobalStore.actions.auth.setSessionState({ isLoading: false })
} else {
captureMessage("AUTH_FAILURE: " + error.message)

InteractionManager.runAfterInteractions(() => {
const errorMode = error.message === "Attempt blocked" ? "attempt blocked" : "no account"
showErrorAlert(errorMode, error)
})
const canBeLinked =
error.error === "User Already Exists" && error.meta && error.meta.existingProviders
if (canBeLinked) {
handleErrorWithAlternativeProviders(error.meta)
return
}
GlobalStore.actions.auth.setSessionState({ isLoading: false })

InteractionManager.runAfterInteractions(() => {
const errorMode = error.message === "Attempt blocked" ? "attempt blocked" : "no account"
showErrorAlert(errorMode, error)
return
})
}
}

const showErrorAlert = (
Expand Down
17 changes: 12 additions & 5 deletions src/app/store/AuthModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionType, AuthService, CreatedAccount } from "@artsy/cohesion"
import { appleAuth } from "@invertase/react-native-apple-authentication"
import CookieManager from "@react-native-cookies/cookies"
import { GoogleSignin } from "@react-native-google-signin/google-signin"
import { GoogleSignin, statusCodes } from "@react-native-google-signin/google-signin"
import * as Sentry from "@sentry/react-native"
import { LegacyNativeModules } from "app/NativeModules/LegacyNativeModules"
import * as RelayCache from "app/system/relay/RelayCache"
Expand Down Expand Up @@ -164,6 +164,7 @@ export interface AuthPromiseResolveType {
export interface AuthPromiseRejectType {
error?: string
message: string
code?: string
meta?: {
email: string
provider: OAuthProvider
Expand Down Expand Up @@ -772,18 +773,24 @@ export const getAuthModel = (): AuthModel => ({
}
}
}
} catch (e) {
} catch (e: any) {
if (statusCodes.SIGN_IN_CANCELLED === e?.code) {
reject(new AuthError(statusCodes.SIGN_IN_CANCELLED))
return
}

if (e instanceof Error) {
if (e.message === "DEVELOPER_ERROR") {
if (e?.message === "DEVELOPER_ERROR") {
reject(
new AuthError(
"Google auth does not work in firebase beta, try again in a playstore beta",
e.message
e?.message
)
)
return
}
reject(new AuthError("Error logging in with google", e.message))

reject(new AuthError("Error logging in with google", e?.message))
return
}
reject(new AuthError("Error logging in with google"))
Expand Down

0 comments on commit 8ff8368

Please sign in to comment.