Skip to main content

Migration guides

There are 2 migrations described here: from Original to Universal Sign In and from the old JS API to the new JS API.

Migrating from Original to Universal Sign In

Migrating from Original to Universal module is mostly about changing the method names: the table summarizes the mapping from Original module's calls to the Universal (OneTap) module's calls:

Original MethodUniversal (OneTap) MethodNotes
configureconfigureSame functionality.
signInSilentlysignInUniversal's signIn attempts sign in without user interaction.
signIncreateAccountUniversal's createAccount is for first-time sign in (but can be used for existing users too).
addScopesrequestAuthorizationSimilar functionality, different parameters. On Android, you can call requestAuthorization without being signed in!
hasPlayServicescheckPlayServicesSame functionality, different name.
getCurrentUserUse signIn responseManage the current user state yourself, or through libraries like Firebase Auth or Supabase Auth.
getTokensUse signIn or requestAuthorizationTokens are included in the response object.
signOutsignOutUniversal requires email/id parameter on web.
revokeAccessNot yet provided by Google.See here.
hasPreviousSignInUse signIn responseCheck for noSavedCredentialFound response type.
clearCachedAccessTokenNot provided, presumably not needed.-

Migrating to new JS API

Version 13 introduced a new JS API, which changes some method response signatures and makes minor changes to error handling (details here). If you're upgrading from version 12 or earlier, you'll need to make some minor adjustments.

Universal Sign In

  1. Add the configure method to your code. This method is required to be called to configure the module.

  2. Change the signIn, createAccount, presentExplicitSignIn, and requestAuthorization methods to use the new apis: That means that the data you previously accessed directly on userInfo (see below - for example userInfo.name) will now be nested in userInfo.data (e.g. userInfo.data.name). See OneTapResponse type:

const signIn = async () => {
try {
- const userInfo = await GoogleOneTapSignIn.signIn({
- webClientId: `autoDetect`, // works only if you use Firebase
- iosClientId: config.iosClientId, // only needed if you're not using Firebase
- });
- setState({ userInfo }); // use e.g. `userInfo.name`
+ const response = await GoogleOneTapSignIn.signIn();
+
+ if (response.type === 'success') {
+ setState({ userInfo: response.data });
+ } else if (response.type === 'noSavedCredentialFound') {
+ // Android and Apple only. No saved credential found, call `createAccount`
+ }

} catch (error) {
if (isErrorWithCode(error)) {
switch (error.code) {
- case statusCodes.NO_SAVED_CREDENTIAL_FOUND:
- // Android and Apple only. No saved credential found, call `createAccount`
- break;
- case statusCodes.SIGN_IN_CANCELLED:
- // sign in was cancelled
- break;
case statusCodes.ONE_TAP_START_FAILED:
// Android-only, you probably have hit rate limiting.
// On Android, you can still call `presentExplicitSignIn` in this case.
break;
case statusCodes.PLAY_SERVICES_NOT_AVAILABLE:
// Android-only: play services not available or outdated
// Web: when calling an unimplemented api (requestAuthorization)
break;
default:
// something else happened
}
} else {
// an error that's not related to google sign in occurred
}
}
};
  1. If requesting offline access in requestAuthorization on Android, add enabled: true:
await GoogleOneTapSignIn.requestAuthorization({
offlineAccess: {
+ enabled: true,
},
});

Original Sign In

  1. Follow step 2. from above for signIn, addScopes and signInSilently methods.
  2. remove SIGN_IN_REQUIRED mentions. This case is now handled with NoSavedCredentialFound object:
const getCurrentUserInfo = async () => {
try {
const response = await GoogleSignin.signInSilently();
+ if (isSuccessResponse(response)) {
+ setState({ userInfo: response.data })
+ } else if (isNoSavedCredentialFoundResponse(response)) {
+ // user has not signed in yet
+ }
- setState({ userInfo: response });
} catch (error) {
- if (error.code === statusCodes.SIGN_IN_REQUIRED) {
- // user has not signed in yet
- } else {
- // some other error
- }
}
};