@@ -26,7 +26,7 @@ const useGoogleLogin = ({
2626} ) => {
2727 const [ loaded , setLoaded ] = useState ( false )
2828
29- function handleSigninSuccess ( res ) {
29+ function handleSignInSuccess ( res ) {
3030 /*
3131 offer renamed response keys to names that match use
3232 */
@@ -56,6 +56,12 @@ const useGoogleLogin = ({
5656 const options = {
5757 prompt
5858 }
59+ // Add to the default scopes (email profile) the additional scopes required if passed via props
60+ // Read more at https://developers.google.com/identity/sign-in/web/reference#gapiauth2offlineaccessoptions
61+ if ( scope ) {
62+ options . scope = scope
63+ }
64+
5965 onRequest ( )
6066 if ( responseType === 'code' ) {
6167 GoogleAuth . grantOfflineAccess ( options ) . then (
@@ -64,7 +70,7 @@ const useGoogleLogin = ({
6470 )
6571 } else {
6672 GoogleAuth . signIn ( options ) . then (
67- res => handleSigninSuccess ( res ) ,
73+ res => handleSignInSuccess ( res ) ,
6874 err => onFailure ( err )
6975 )
7076 }
@@ -80,6 +86,7 @@ const useGoogleLogin = ({
8086 'google-login' ,
8187 jsSrc ,
8288 ( ) => {
89+ // Not passing 'scope' to the params will use the default "email profile" scope.
8390 const params = {
8491 client_id : clientId ,
8592 cookie_policy : cookiePolicy ,
@@ -89,7 +96,6 @@ const useGoogleLogin = ({
8996 discoveryDocs,
9097 ux_mode : uxMode ,
9198 redirect_uri : redirectUri ,
92- scope,
9399 access_type : accessType
94100 }
95101
@@ -107,7 +113,7 @@ const useGoogleLogin = ({
107113 const signedIn = isSignedIn && res . isSignedIn . get ( )
108114 onAutoLoadFinished ( signedIn )
109115 if ( signedIn ) {
110- handleSigninSuccess ( res . currentUser . get ( ) )
116+ handleSignInSuccess ( res . currentUser . get ( ) )
111117 }
112118 }
113119 } ,
@@ -126,7 +132,7 @@ const useGoogleLogin = ({
126132 if ( isSignedIn && GoogleAuth . isSignedIn . get ( ) ) {
127133 setLoaded ( true )
128134 onAutoLoadFinished ( true )
129- handleSigninSuccess ( GoogleAuth . currentUser . get ( ) )
135+ handleSignInSuccess ( GoogleAuth . currentUser . get ( ) )
130136 } else {
131137 setLoaded ( true )
132138 onAutoLoadFinished ( false )
0 commit comments