首页 > 解决方案 > 我目前正在使用 Google OAuth2.0 构建一个 React 应用程序,完成登录后它不会重定向

问题描述

使用 OAut2.0 构建了一个简单的反应登录页面,但登录后不会重定向到新页面,而是返回登录页面。

我希望我的页面在登录后重定向到仪表板。

Google API 控制台已配置授权 JavaScript 源 (URI) 和授权重定向 URI。

如果可能的话,您可以分享如何将护照 JS 用于 reactjs。

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import GoogleLogin from 'react-google-login'; // or import { GoogleLogin } from 'react-google-login';

const responseGoogle = (response) => {   console.log(response); } 
ReactDOM.render(<GoogleLogin
    clientId="658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"
    buttonText="Login"
    onSuccess={responseGoogle}
    onFailure={responseGoogle}
    cookiePolicy={'single_host_origin'}/>, 
    document.getElementById('googleButton') );

标签: node.jsreactjsoauth-2.0passport.js

解决方案


因此,在您的responseGoogle方法中,console.log()您可以运行return this.history.push("/dashboard")它而不是运行它,而是重定向到您的仪表板或仪表板的路由,或者您可以将您的响应片段发送到控制台以供我们查看


推荐阅读