我在输入emailID后创建了登录界面,密码用户应该可以登录,并且应该能够查看VenueList组件,即所有场地的列表。我使用auth0进行身份验证。我收到类型错误如何解决?
我创建了VenueList组件,在输入电子邮件和密码后应该可以查看。
Login.js:
import React, { Component } from "react";
import { View, Text, StyleSheet, Button, TextInput, KeyboardAvoidingView, ActivityIndicator } from "react-native";
import Auth0 from "react-native-auth0";
var credentials = require('./auth0-credentials');
const auth0 = new Auth0(credentials);
export default class Login extends Component {
constructor(props) {
super(props);
this.state = { accessToken: null };
}
_onLogin = () => {
auth0.webAuth
.authorize({
scope: 'openid profile',
audience: 'https://' + credentials.domain + '/userinfo'
})
.then(credentials => {
Alert.alert(
'Success',
'AccessToken: ' + credentials.accessToken,
[{ text: 'OK', onPress: () => console.log('OK Pressed') }],
{ cancelable: false }
);
this.setState({ accessToken: credentials.accessToken });
})
.catch(error => console.log(error));
};
_onLogout = () => {
if (Platform.OS === 'android') {
this.setState({ accessToken: null });
} else {
auth0.webAuth
.clearSession({})
.then(success => {
this.setState({ accessToken: null });
})
.catch(error => console.log(error));
}
};
render() {
let loggedIn = this.state.accessToken === null ? false : true;
return (
<View style={styles.container}>
<Text style={styles.header}>Auth0Sample - Login</Text>
<Text>
You are {loggedIn ? '' : 'not '}logged in.
</Text>
<Button
onPress={loggedIn ? this._onLogout : this._onLogin}
title={loggedIn ? 'Log Out' : 'Log In'}
/>
</View>
);
}
}
在auth0-credentials.js中:
module.exports = {
clientId: "{AUTH0_CLIENT_ID}",
domain: "{AUTH0_DOMAIN}"
};
截图:
react-native link react-native-sensitive-info
尝试此命令并重建