@react-oauth/google
Advanced tools
Comparing version
@@ -73,2 +73,5 @@ /// <reference types="react" /> | ||
} | ||
interface GoogleCredentialResponse extends CredentialResponse { | ||
client_id?: string; | ||
} | ||
interface GsiButtonConfiguration { | ||
@@ -336,2 +339,2 @@ /** The button [type](https://developers.google.com/identity/gsi/web/reference/js-reference#type): icon, or standard button */ | ||
export { CodeClientConfig, CodeResponse, CredentialResponse, GoogleLogin, GoogleLoginProps, GoogleOAuthProvider, GsiButtonConfiguration, IdConfiguration, MomenListener, OverridableTokenClientConfig, PromptMomentNotification, TokenClientConfig, TokenResponse, UseGoogleLoginOptions, UseGoogleLoginOptionsAuthCodeFlow, UseGoogleLoginOptionsImplicitFlow, googleLogout, hasGrantedAllScopesGoogle, hasGrantedAnyScopeGoogle, useGoogleLogin, useGoogleOneTapLogin }; | ||
export { CodeClientConfig, CodeResponse, CredentialResponse, GoogleCredentialResponse, GoogleLogin, GoogleLoginProps, GoogleOAuthProvider, GsiButtonConfiguration, IdConfiguration, MomenListener, OverridableTokenClientConfig, PromptMomentNotification, TokenClientConfig, TokenResponse, UseGoogleLoginOptions, UseGoogleLoginOptionsAuthCodeFlow, UseGoogleLoginOptionsImplicitFlow, googleLogout, hasGrantedAllScopesGoogle, hasGrantedAnyScopeGoogle, useGoogleLogin, useGoogleOneTapLogin }; |
@@ -53,2 +53,8 @@ import React, { useState, useRef, useEffect, createContext, useMemo, useContext, useCallback } from 'react'; | ||
function extractClientId(credentialResponse) { | ||
var _a; | ||
const clientId = (_a = credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.clientId) !== null && _a !== void 0 ? _a : credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.client_id; | ||
return clientId; | ||
} | ||
const containerHeightMap = { large: 40, medium: 32, small: 20 }; | ||
@@ -72,6 +78,11 @@ function GoogleLogin({ onSuccess, onError, useOneTap, promptMomentNotification, type = 'standard', theme = 'outline', size = 'large', text, shape, logo_alignment, width, locale, ...props }) { | ||
var _a; | ||
if (!credentialResponse.clientId || !credentialResponse.credential) { | ||
if (!(credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.credential)) { | ||
return (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef); | ||
} | ||
onSuccessRef.current(credentialResponse); | ||
const { credential, select_by } = credentialResponse; | ||
onSuccessRef.current({ | ||
credential, | ||
clientId: extractClientId(credentialResponse), | ||
select_by, | ||
}); | ||
}, | ||
@@ -167,6 +178,11 @@ ...props, | ||
var _a; | ||
if (!credentialResponse.clientId || !credentialResponse.credential) { | ||
if (!(credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.credential)) { | ||
return (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef); | ||
} | ||
onSuccessRef.current(credentialResponse); | ||
const { credential, select_by } = credentialResponse; | ||
onSuccessRef.current({ | ||
credential, | ||
clientId: extractClientId(credentialResponse), | ||
select_by, | ||
}); | ||
}, | ||
@@ -173,0 +189,0 @@ hosted_domain, |
@@ -61,2 +61,8 @@ 'use strict'; | ||
function extractClientId(credentialResponse) { | ||
var _a; | ||
const clientId = (_a = credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.clientId) !== null && _a !== void 0 ? _a : credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.client_id; | ||
return clientId; | ||
} | ||
const containerHeightMap = { large: 40, medium: 32, small: 20 }; | ||
@@ -80,6 +86,11 @@ function GoogleLogin({ onSuccess, onError, useOneTap, promptMomentNotification, type = 'standard', theme = 'outline', size = 'large', text, shape, logo_alignment, width, locale, ...props }) { | ||
var _a; | ||
if (!credentialResponse.clientId || !credentialResponse.credential) { | ||
if (!(credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.credential)) { | ||
return (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef); | ||
} | ||
onSuccessRef.current(credentialResponse); | ||
const { credential, select_by } = credentialResponse; | ||
onSuccessRef.current({ | ||
credential, | ||
clientId: extractClientId(credentialResponse), | ||
select_by, | ||
}); | ||
}, | ||
@@ -175,6 +186,11 @@ ...props, | ||
var _a; | ||
if (!credentialResponse.clientId || !credentialResponse.credential) { | ||
if (!(credentialResponse === null || credentialResponse === void 0 ? void 0 : credentialResponse.credential)) { | ||
return (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef); | ||
} | ||
onSuccessRef.current(credentialResponse); | ||
const { credential, select_by } = credentialResponse; | ||
onSuccessRef.current({ | ||
credential, | ||
clientId: extractClientId(credentialResponse), | ||
select_by, | ||
}); | ||
}, | ||
@@ -181,0 +197,0 @@ hosted_domain, |
{ | ||
"name": "@react-oauth/google", | ||
"version": "0.2.8", | ||
"version": "0.4.0", | ||
"description": "Google OAuth2 using Google Identity Services for React 🚀", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
66200
2.81%763
4.52%