- SDK Version:48
- Platforms(Android/iOS)
I have followed facebook authentcation guide in expo official document but I’m always getting an error from facebook browser something went wrong
here is the link of the guide
https://docs.expo.dev/guides/facebook-authentication/
I’m not sure if the library is deprecated or not because there is no mention for it in the document
import { useState, useEffect } from "react";
import { Button, Image, StyleSheet, Text, View } from "react-native";
import * as AuthSession from "expo-auth-session";
import * as Facebook from "expo-auth-session/providers/facebook";
import * as WebBrowser from "expo-web-browser";
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [user, setUser] = useState(null);
const [request, response, promptAsync] = Facebook.useAuthRequest({
clientId: "4127407154196869",
});
console.log(request);
if (request) {
console.log(
"You need to add this url to your authorized redirect urls on your Facebook app: " +
request.redirectUri
);
}
useEffect(() => {
if (response && response.type === "success" && response.authentication) {
(async () => {
const userInfoResponse = await fetch(
`https://graph.facebook.com/me?access_token=${response.authentication.accessToken}&fields=id,name,picture.type(large)`
);
const userInfo = await userInfoResponse.json();
setUser(userInfo);
})();
}
}, [response]);
const handlePressAsync = async () => {
const result = await promptAsync();
console.log("result", result);
if (result.type !== "success") {
alert("Uh oh, something went wrong");
return;
}
};
return (
<View style={styles.container}>
{user ? (
<Profile user={user} />
) : (
<Button
disabled={!request}
title="Sign in with Facebook"
onPress={handlePressAsync}
/>
)}
</View>
);
}
function Profile({ user }) {
return (
<View style={styles.profile}>
<Image source={{ uri: user.picture.data.url }} style={styles.image} />
<Text style={styles.name}>{user.name}</Text>
<Text>ID: {user.id}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
profile: {
alignItems: "center",
},
name: {
fontSize: 20,
},
image: {
width: 100,
height: 100,
borderRadius: 50,
},
});
app.json:
{
"expo": {
"name": "facebook-auth",
"slug": "facebook-auth",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"scheme": "com.facebook-auth.play",
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.facebook-auth.play"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.facebook-auth.play"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}