首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重定向时使用React- Google -登录问题进行Google身份验证

重定向时使用React- Google -登录问题进行Google身份验证
EN

Stack Overflow用户
提问于 2021-06-24 15:37:29
回答 1查看 1K关注 0票数 0

我有一个npm包react-google-login的问题。问题是我有一个redirectUri传递到组件中,但是当我尝试用弹出窗口重定向时,什么也没有发生,但是当我添加uxMode=' redirect‘时,它起作用了,但它给了我一个非常长的url,这是我不喜欢的东西。有没有办法让弹出版本的重定向起作用?

下面是我的代码,clientID被删除了:

代码语言:javascript
复制
import React from 'react';
import GoogleLogin from 'react-google-login';
import ChatRoom from './ChatRoom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faGoogle } from '@fortawesome/free-brands-svg-icons';
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
import {Link} from 'react-router-dom';

const responseGoogle = (res) => {
    console.log('Failed');
}

const successLogin = () => {
    console.log('success');
}

const Authentication = () => {
    return (
            <div className='auth-wrapper'>
                <div className="auth-container">
                    <h1 className="auth-header">Choose Your Sign in Method</h1>
                    <div className="btn-container2">
                        <GoogleLogin 
                            clientId="none"
                            buttonText="Sign in with Google"
                            onSuccess={successLogin}
                            onFailure={responseGoogle}
                            cookiePolicy={'single_host_origin'}
                            uxMode='popup'
                            redirectUri='http://localhost:3000/ChatRoom'
                            render={renderProps => (
                                <button className="btn2 btn-primary2 animate shake" onClick={renderProps.onClick} disabled={renderProps.disabled}><FontAwesomeIcon size='lg' icon={faGoogle} /> Sign in with Google</button>
                            )}
                        />
                        <Link to='/ChatRoom'>
                            <button className="space btn2 btn-primary2 animate shake">
                                <FontAwesomeIcon size='lg' icon={faQuestionCircle} /> Continue as Guest
                            </button>
                        </Link>
                    </div>
                </div>
            </div>
    )
}

export default Authentication
EN

回答 1

Stack Overflow用户

发布于 2021-06-25 23:00:44

基本上,我所要做的就是在react-router-dom中使用useHistory,并利用history.push('/ page ');在用户通过身份验证时导航到页面。

代码语言:javascript
复制
let history = useHistory();
// Redirects user after authentication to the ChatRoom
const successLogin = () => {

    history.push('/ChatRoom');

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68111452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档