node.js - 我目前正在使用 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') );
解决方案
因此,在您的responseGoogle
方法中,console.log()
您可以运行return this.history.push("/dashboard")
它而不是运行它,而是重定向到您的仪表板或仪表板的路由,或者您可以将您的响应片段发送到控制台以供我们查看
推荐阅读
- node.js - 如何在没有`gcloud app deploy`的情况下在GCP上部署Node.js express服务器?
- ios - iOS 基于调试构建,但在发布模式下返回“No such module ...”
- batch-file - 为什么不立即设置批处理变量?
- python - 如何通过 numpy.concatenate 添加一列?
- java - KeyListener 未在 JPanel 中实例化
- c++ - openssl 解密功能无法正常工作
- javascript - React Native 中是否有与 sessionStorage 等价的东西?
- javascript - 前端过滤表 - Vue.JS
- phone-number - 如何根据 E.164 分析法国电话号码
- multithreading - 从 VPS 脚本测试“300 个线程”,可以吗?如何?