Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new js api #1326

Merged
merged 5 commits into from
Sep 1, 2024
Merged

feat: new js api #1326

merged 5 commits into from
Sep 1, 2024

Conversation

vonovak
Copy link
Member

@vonovak vonovak commented Sep 1, 2024

Why: the current API is a bit clumsy when it comes to handling errors and reacting to them

ex: to handle the sign in cancellation, you're required to implement this in the catch block. It's not unlikely that the code handling cancellation will be empty:

// OLD CODE
} catch (error) {
    if (isErrorWithCode(error)) {
      switch (error.code) {
        case statusCodes.SIGN_IN_CANCELLED:
          // sign in was cancelled
          break;
    } else {
      // an error that's not related to google sign in occurred
    }
  }

The changes in this PR mean that only "real errors" are propagated to the catch block. Cancellation is handled in the try block:

// NEW CODE
    const { type, data } = await GoogleSignin.signIn();
    if (type === 'success') {
      setState({ userInfo: data });
    } else {
      // sign in was cancelled by user
    }

Same change is present for addScopes and signInSilently - statusCodes.SIGN_IN_REQUIRED was removed and is now handled as follows:

    const { type, data } = await GoogleSignin.signInSilently();
    if (isSuccessResponse(response)) {
      setState({ userInfo: response.data });
    } else if (isNoSavedCredentialFoundResponse(response)) {
      // user has not signed in yet
    }

This makes the api a little nicer to work with and the non-success cases are more explicitly visible in the API.

additionally, this PR fixes #1070

@vonovak vonovak merged commit 04c3c64 into master Sep 1, 2024
2 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 1, 2024
# [13.0.0](v12.2.1...v13.0.0) (2024-09-01)

### Features

* refactored js apis ([#1326](#1326)) ([04c3c64](04c3c64))

Please note there's a [paid version of the package](https://react-native-google-signin.github.io/docs/install) with some extra features available.

### BREAKING CHANGES

* function signatures have changed
Copy link

github-actions bot commented Sep 1, 2024

🎉 This PR is included in version 13.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@vonovak vonovak deleted the feat/new-api branch September 16, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-8
1 participant