使用 react-native-fbsdk 登录后导航失败
Navigation failed after logging in with react-native-fbsdk
我正在使用 FBSDK 在 React Native 中进行注册。我需要姓名、姓氏和电子邮件,以便将其传递到注册屏幕并在那里自动填写提到的字段。这是我在登录屏幕中的代码:
async _fbAuth() {
//console.log("that", that);
let { isCancelled } = await LoginManager.logInWithReadPermissions(['public_profile','user_posts', 'email','user_birthday']);
if ( !isCancelled ) {
let data = await AccessToken.getCurrentAccessToken();
let token = data.accessToken.toString();
// await afterLoginComplete(token);
const response = await fetch(
`https://graph.facebook.com/me?fields=id,email,name,first_name,last_name,gender,picture,cover&access_token=${token}`);
let result = await response.json();
this.setState({result});
console.log('result result result ', result);
//navigate to complete the registration.
this.props.navigation.navigate('Reg_1', {name: this.state.result.name, email: this.state.result.email, surname: this.state.result.last_name })
}
else {
console.log('Login incomplete');
}
}
我还有这个按钮来调用函数:
<ButtonFB
onPress={ this._fbAuth}
isLoading={false}
isEnabled={true}
label={I18n.t("Accedi_con_Facebook")}
style={commonStyle.Button}
/>
一切正常,数据检索正常。唯一的问题是导航和 setSate 的部分。我的问题是 'this' 在使用 facebook 登录期间丢失了。使用 facebook 登录后,我收到以下警告。
Possible: Unhandled promise rejection (id:0): type error:
this.setState is not a function
我也试过绑定_fbAuth
的功能,但是不行。你能帮我解决这个问题吗?提前致谢。
您需要将函数绑定为
_fbAuth = async () => {}
因为 this
未在 _fbAuth
函数中引用。
有关更多信息,请查看此 artice
我正在使用 FBSDK 在 React Native 中进行注册。我需要姓名、姓氏和电子邮件,以便将其传递到注册屏幕并在那里自动填写提到的字段。这是我在登录屏幕中的代码:
async _fbAuth() {
//console.log("that", that);
let { isCancelled } = await LoginManager.logInWithReadPermissions(['public_profile','user_posts', 'email','user_birthday']);
if ( !isCancelled ) {
let data = await AccessToken.getCurrentAccessToken();
let token = data.accessToken.toString();
// await afterLoginComplete(token);
const response = await fetch(
`https://graph.facebook.com/me?fields=id,email,name,first_name,last_name,gender,picture,cover&access_token=${token}`);
let result = await response.json();
this.setState({result});
console.log('result result result ', result);
//navigate to complete the registration.
this.props.navigation.navigate('Reg_1', {name: this.state.result.name, email: this.state.result.email, surname: this.state.result.last_name })
}
else {
console.log('Login incomplete');
}
}
我还有这个按钮来调用函数:
<ButtonFB
onPress={ this._fbAuth}
isLoading={false}
isEnabled={true}
label={I18n.t("Accedi_con_Facebook")}
style={commonStyle.Button}
/>
一切正常,数据检索正常。唯一的问题是导航和 setSate 的部分。我的问题是 'this' 在使用 facebook 登录期间丢失了。使用 facebook 登录后,我收到以下警告。
Possible: Unhandled promise rejection (id:0): type error: this.setState is not a function
我也试过绑定_fbAuth
的功能,但是不行。你能帮我解决这个问题吗?提前致谢。
您需要将函数绑定为
_fbAuth = async () => {}
因为 this
未在 _fbAuth
函数中引用。
有关更多信息,请查看此 artice