我的Google身份验证有问题,显示了由用户关闭的错误'
我正在尝试在我的Web应用程序中实现Google身份验证,但是我一直遇到错误。 我在Google Console网站上生成了令牌,但是当我尝试登录时,我会收到错误:“ popup_closed_by_user”,当在控制台中时,我应该看到Google帐户的凭据。以下是身份验证的代码:
import React, {useState} from 'react';
import {Avatar, Button, Paper, Grid, Typography, Container, TextField} from '@material-ui/core';
import {GoogleLogin} from 'react-google-login';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import useStyles from './styles';
import Input from './Input';
import Icon from './icon';
const Auth=()=>{
const classes=useStyles();
const [showPassword, setShowPassword] =useState(false);
const [isSignup, setIsSignup] = useState(false);
const handleShowPassword=()=>setShowPassword((prevShowPassword)=> !prevShowPassword);
const handleSubmit=()=>{
};
const handleChange=()=>{
};
const switchMode=()=>{
setIsSignup((prevIsSignUp)=> !prevIsSignUp);
handleShowPassword(false);
};
const googleSuccess=async (res)=>{
console.log(res);
};
const googleFailure=(error)=>{
console.log(error);
console.log("Google Sign In was unsuccessful. Try Again Later.");
};
return (
<Container component="main" maxWidth="xs">
<Paper className={classes.paper} elevation={3}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon/>
</Avatar>
<Typography variant="h5">{isSignup ? 'Sign Up' : 'Sign In'}</Typography>
<form className={classes.form} onSubmit={handleSubmit}>
<Grid container spacing={2}>
{
isSignup && (
<>
<Input name="firstName" label="First Name" handleChange={handleChange} autoFocus half/>
<Input name="lastName" label="Last Name" handleChange={handleChange} half/>
</>
)}
<Input name="email" label="Email Address" handleChange={handleChange} type="email"/>
<Input name="password" label="Password" handleChange={handleChange} type={showPassword ? "text" : "password"} handleShowPassword={handleShowPassword}/>
{
isSignup && <Input name="confirmPassword" label="Repeat Password" handleChange={handleChange} type="password"/>
}
</Grid>
<Button type="submit" fullWidth variant="contained" color="primary" className={classes.submit}>
{isSignup ? 'Sign Up' : 'Sign In'}
</Button>
<GoogleLogin
clientId=""
render={(renderProps)=>(
<Button
className={classes.googleButton}
color="primary"
fullWidth
onClick={renderProps.onClick}
disabled={renderProps.disabled}
startIcon={<Icon/>}
variant="contained"
>
Google Sign In
</Button>
)}
onSuccess={googleSuccess}
onFailure={googleFailure}
cookiePolicy="single_host_origin"
/>
<Grid container justifyContent="flex-end">
<Grid item>
<Button onClick={switchMode}>
{isSignup ? 'Already have an account? Sign In' : "Don't have an account? Sign Up"}
</Button>
</Grid>
</Grid>
</form>
</Paper>
</Container>
);
};
export default Auth
我已经生成了令牌并将其放入代码中,但是我将其删除了此帖子,我也清除了缓存,并在浏览器设置中取消了“块第三方cookie cookies按钮”。 你能帮我吗?
I am trying to implement Google authentication in my web application, but I keep getting an error.
I generated my token on the Google Console Website, but when I try to sign in I get the error: "popup_closed_by_user", when in the console I should have seen the credentials of the google account. Below is the code for the authentication:
import React, {useState} from 'react';
import {Avatar, Button, Paper, Grid, Typography, Container, TextField} from '@material-ui/core';
import {GoogleLogin} from 'react-google-login';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import useStyles from './styles';
import Input from './Input';
import Icon from './icon';
const Auth=()=>{
const classes=useStyles();
const [showPassword, setShowPassword] =useState(false);
const [isSignup, setIsSignup] = useState(false);
const handleShowPassword=()=>setShowPassword((prevShowPassword)=> !prevShowPassword);
const handleSubmit=()=>{
};
const handleChange=()=>{
};
const switchMode=()=>{
setIsSignup((prevIsSignUp)=> !prevIsSignUp);
handleShowPassword(false);
};
const googleSuccess=async (res)=>{
console.log(res);
};
const googleFailure=(error)=>{
console.log(error);
console.log("Google Sign In was unsuccessful. Try Again Later.");
};
return (
<Container component="main" maxWidth="xs">
<Paper className={classes.paper} elevation={3}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon/>
</Avatar>
<Typography variant="h5">{isSignup ? 'Sign Up' : 'Sign In'}</Typography>
<form className={classes.form} onSubmit={handleSubmit}>
<Grid container spacing={2}>
{
isSignup && (
<>
<Input name="firstName" label="First Name" handleChange={handleChange} autoFocus half/>
<Input name="lastName" label="Last Name" handleChange={handleChange} half/>
</>
)}
<Input name="email" label="Email Address" handleChange={handleChange} type="email"/>
<Input name="password" label="Password" handleChange={handleChange} type={showPassword ? "text" : "password"} handleShowPassword={handleShowPassword}/>
{
isSignup && <Input name="confirmPassword" label="Repeat Password" handleChange={handleChange} type="password"/>
}
</Grid>
<Button type="submit" fullWidth variant="contained" color="primary" className={classes.submit}>
{isSignup ? 'Sign Up' : 'Sign In'}
</Button>
<GoogleLogin
clientId=""
render={(renderProps)=>(
<Button
className={classes.googleButton}
color="primary"
fullWidth
onClick={renderProps.onClick}
disabled={renderProps.disabled}
startIcon={<Icon/>}
variant="contained"
>
Google Sign In
</Button>
)}
onSuccess={googleSuccess}
onFailure={googleFailure}
cookiePolicy="single_host_origin"
/>
<Grid container justifyContent="flex-end">
<Grid item>
<Button onClick={switchMode}>
{isSignup ? 'Already have an account? Sign In' : "Don't have an account? Sign Up"}
</Button>
</Grid>
</Grid>
</form>
</Paper>
</Container>
);
};
export default Auth
I have generated the token and put it in my code, but I deleted it for this post and I also cleared my cache and unchecked the "Block third-party cookies button" in my browser settings.
Could you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论