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 Method | Universal (OneTap) Method | Notes |
---|---|---|
configure | configure | Same functionality. |
signInSilently | signIn | Universal's signIn attempts sign in without user interaction. |
signIn | createAccount | Universal's createAccount is for first-time sign in (but can be used for existing users too). |
addScopes | requestAuthorization | Similar functionality, different parameters. On Android, you can call requestAuthorization without being signed in! |
hasPlayServices | checkPlayServices | Same functionality, different name. |
getCurrentUser | Use signIn response | Manage the current user state yourself, or through libraries like Firebase Auth or Supabase Auth. |
getTokens | Use signIn or requestAuthorization | Tokens are included in the response object. |
signOut | signOut | Universal requires email/id parameter on web. |
revokeAccess | Not yet provided by Google. | See here. |
hasPreviousSignIn | Use signIn response | Check for noSavedCredentialFound response type. |
clearCachedAccessToken | Not 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
-
Add the
configure
method to your code. This method is required to be called to configure the module. -
Change the
signIn
,createAccount
,presentExplicitSignIn
, andrequestAuthorization
methods to use the new apis: That means that the data you previously accessed directly onuserInfo
(see below - for exampleuserInfo.name
) will now be nested inuserInfo.data
(e.g.userInfo.data.name
). SeeOneTapResponse
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
}
}
};
- If requesting offline access in
requestAuthorization
on Android, addenabled: true
:
await GoogleOneTapSignIn.requestAuthorization({
offlineAccess: {
+ enabled: true,
},
});
Original Sign In
- Follow step 2. from above for
signIn
,addScopes
andsignInSilently
methods. - remove
SIGN_IN_REQUIRED
mentions. This case is now handled withNoSavedCredentialFound
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
- }
}
};