I want to use the expo google auth session provider as followed:
const [accessToken, setAccessToken] = useState<string | null | undefined>(null);
const [user, setUser] = useState(null);
const [request, response, promtAsync] = Google.useIdTokenAuthRequest({
expoClientId: '###',
});
useEffect(() => {
if (response?.type === 'success') {
console.log(response);
setAccessToken(response?.authentication?.accessToken);
}
accessToken && fetchGoogleUserInfo();
}, [accessToken, response]);
const fetchGoogleUserInfo = async () => {
const response = await fetch('https://www.googleapis.com/userinfo/v2/me', {
headers: {
Authorization: `Bearer${accessToken}`,
},
});
const useInfo = await response.json();
setUser(useInfo);
}
This is completely as the documentation states: https://docs.expo.dev/guides/authentication/#google However my response i get back has the authentication returning null. This is a problem since i need it to do my google api call to fetch data of the user that wants to log in.
Anyone any idea to why this is happening?
I am using expo 46.0.16, react-native 0.69.6 and expo-auth-session 3.7.1.
I don't really know why this is happening since i see other do it and it works perfectly fine.
Youtube link: https://www.youtube.com/watch?v=hmZm_jPvWWM&t=710s
Also this guys does get the response he needs to fetch the user data...: expo-auth-session/providers/google Google.useAuthRequest
UPDATE: made kind of a typo mistake==> useIdTokenAuthRequest for id_token in api call and useAuthRequest for getting the accessToken in api call...