I am trying to implement Login with Google with expo-auth-session, and I am using below version:
- “expo-auth-session”: “^4.0.3”
- “expo-web-browser”: “^12.1.1”,
Below is my app.js code:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, View, Text, Image, Button } from 'react-native';
import * as Google from 'expo-auth-session/providers/google';
import * as WebBrowser from 'expo-web-browser';
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [accessToken, setAccessToken] = React.useState();
const [userInfo, setUserInfo] = React.useState();
const [message, setMessage] = React.useState();
const [request, response, promptAsync] = Google.useAuthRequest({
androidClientId: "*********************************************",
iosClientId: "*********************************************",
expoClientId: "*********************************************"
});
React.useEffect(() => {
setMessage(JSON.stringify(response));
if (response?.type === "success") {
setAccessToken(response.authentication.accessToken);
}
}, [response]);
async function getUserData() {
let userInfoResponse = await fetch("https://www.googleapis.com/userinfo/v2/me", {
headers: { Authorization: `Bearer ${accessToken}`}
});
userInfoResponse.json().then(data => {
setUserInfo(data);
});
}
function showUserInfo() {
if (userInfo) {
return (
<View>
<Image source={{uri: userInfo.picture}} />
<Text>Welcome {userInfo.name}</Text>
<Text>{userInfo.email}</Text>
</View>
);
}
}
return (
<View >
{showUserInfo()}
<Button
title={accessToken ? "Get User Data" : "Login"}
onPress={accessToken ? getUserData : () => { promptAsync({useProxy: false, showInRecents: true}) }}
/>
<StatusBar style="auto" />
</View>
);
}
Error I am getting:
Error: Cannot use the AuthSession proxy because the project full name is not defined. Prefer AuthRequest (with the useProxy option set to false) in combination with an Expo Development Client build of your application. To continue using the AuthSession proxy, specify the project full name (@owner/slug) using the projectNameForProxy option.
Any support is appreciated.