使用 Amplify 和 React Native 实现自定义登录,需要以下步骤:
yarn add aws-amplify aws-amplify-react-native @react-native-community/netinfo
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
import { Auth } from 'aws-amplify';
class SignIn extends Component {
state = {
username: '',
password: '',
};
signIn = async () => {
const { username, password } = this.state;
try {
await Auth.signIn(username, password);
console.log('登录成功');
} catch (error) {
console.log('登录失败:', error);
}
};
render() {
const { username, password } = this.state;
return (
this.setState({ username: text })} placeholder="请输入用户名" />
this.setState({ password: text })} placeholder="请输入密码" />
);
}
}
import SignIn from './components/SignIn';
export default class App extends Component {
render() {
return (
);
}
}
这样就可以使用 Amplify 和 React Native 实现自定义登录了。
上一篇:AmplifyReact构建失败,报错在'/codebuild/output/src313005886/src/client-portal/src'中找不到'./components/...'