OnSuccess would be better to return Credential containing method to get user profile
Hi, thanks for your great work. This helps me a lot! However, I think it would be better to add the feature to get user profile when onSuccess is called, because most of client dev will use the info of user profile, much more than token or clientId. it can be additional, for instance, return Credential which contains getProfile(), so that dev can easily get the result of user profile. This feature can be simply added with logic below.
const base64Payload = response.credential.split('.')[1]; //value 0 -> header, 1 -> payload, 2 -> VERIFY SIGNATURE
const payload = Buffer.from(base64Payload, 'base64');
const userProfile = JSON.parse(payload);
return userProfile;
If I miss something, please let me know!
Yes I also needed that
Hello @Hyunhum Thank you for your suggestion,
I tried to make the package to have a similar API for all cases
- GoogleLogin
- useGoogleLogin (implicit flow)
- useGoogleLogin (authorization code flow)
the issue was, for each case, google returns a different response for GoogleLogin google just returns id_token which includes user info directly encoded in base64 which we can decode in multiple ways (one of them is your suggestion) But in useGoogleLogin
- implicit flow -> google returns access_token to communicate with google APIs, & to get profile info we can send HTTP request to https://www.googleapis.com/oauth2/v3/userinfo
- authorization code flow -> google returns code which we can exchange with our backend, and for profile, info backend can decode id_token on the server or we can decode id on the client
if I made decoding id_token for first case only as it's direct return from google, Any user of the package will expect the same behavior for the hooks to return also user profile
so I sticked with google response & decoding is the responsible of the developer (which is small step & easy)