这将是我当前的代码,它停止工作:
import React, { Component } from "react";
import Auth from "../../helper/auth";
import PropTypes from "prop-types";
import logo from "../../img/logo.png";
import { Link } from "react-router-dom";
import GoogleLogin from "react-google-login";
// import * as config from "../../config/config";
class Login extends Component {
onSuccess = (googleUser) => {
Auth.setStorage(googleUser);
this.props.getLoggedUser(googleUser.profileObj.email);
this.props.history.push("/home");
};
onFailure = (error) => {
alert(error);
};
componentWillMount() {
if (this.props.loggedUser != null) {
this.props.history.push("/home");
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.loggedUser != null) {
this.props.history.push("/home");
}
}
render() {
return (
<div className="container">
<div className="container container__login">
<div className="login__section">
<img
src={logo}
alt="EMS Mars logo"
className="login__section__logo"
/>
<h4>Welcome to Mars EMS! </h4>
<p className="no-data" style={{ marginBottom: "-.25rem" }}>
Please sign in with your Google account!
</p>
<br />
<br />
<GoogleLogin
buttonText="log in with Google"
className="btn-primary btn-login"
onSuccess={this.onSuccess}
onFailure={this.onFailure}
/>
<div className="intro">
<ul>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/privacy">Privacy Policy</Link>
</li>
<li>
<Link to="/terms">Terms And Conditions</Link>
</li>
<li style={{ marginTop: ".6rem" }}>Made by Dzenis H.</li>
<li>© {new Date().getFullYear()}</li>
</ul>
</div>
</div>
</div>
</div>
);
}
}
Login.propTypes = {
loggedUser: PropTypes.string,
getLoggedUser: PropTypes.func.isRequired,
};
export default Login;
我尝试了许多npm包,并使用了Google的官方文档,但我似乎无法使其工作。
1条答案
按热度按时间nue99wik1#
这就是解决方案: