我试图使用Passport.js授权谷歌OAuth2上Node.js。我整个星期都在尝试让它工作,但不知道为什么它不工作,所以我现在求助于堆栈以获得一些潜在的帮助。我已经尝试了在线论坛上提供的类似问题的所有解决方案。
每次发送请求时,它都会返回 TokenError: Bad Request,但是,它能够通过 console.log 记录所需的数据,所以这对我来说表明令牌实际上是成功的。我无法解释为什么会发生这种情况。
我尝试在回调请求中更具体,例如http://localhost:3000/auth/google/redirect。我已经尝试了所有其他类型的 Oauth 类型谷歌有节点服务器、Web 应用程序、html 等。我尝试了不同的端口。
授权路线
const router = require('express').Router();
const passport = require('passport');
// auth login
router.get('/login', (req, res) => {
res.render('login', { user: req.user });
});
// auth logout
router.get('/logout', (req, res) => {
// handle with passport
res.send('logging out');
});
// auth with google+
router.get('/google', passport.authenticate('google', {
scope: ['profile']
}));
// callback route for google to redirect to
// hand control to …Run Code Online (Sandbox Code Playgroud) 在尝试将两个数组添加到一起时,我遇到了一些奇怪的行为。每个数组块的长度为 50 个项目。我的清单永远不会超过 50。
我已经尝试过使用扩展运算符和 concat 方法,使用和不使用包装函数。没有任何效果
setWordList(wordList => wordList.concat(msg))
setWordList(wordList => [...wordList, msg])
setWordList([...wordList, msg])
setWordList(wordList.concat(msg))
Run Code Online (Sandbox Code Playgroud)
const [wordList, setWordList] = useState([])
const [isSearching, setIsSearching] = useState(true)
const loadMoreList = (data) => {
console.log(data)
setIsSearching(true)
let already = []
for(let i = 0; i < wordList.length; i++){
already.push({_id: wordList[i]._id})
}
console.log(already)
socket.current.emit('get word list more', {filter: data.filter, already: already});
}
socket.current.on('word list in', (msg) => {
setWordList(wordList => [...wordList, msg])
console.log(msg)
setIsSearching(false)
});
Run Code Online (Sandbox Code Playgroud)
示例数据(数组长度 = 50)
[{
definition: "1. aufhören …Run Code Online (Sandbox Code Playgroud) 我完全不知道为什么这不起作用,我是在 React 中使用 Hooks 的新手,但想尝试一下。
这个应用程序基本上使用 sockets-auth 服务器将 sockets.io 连接到服务器每 1 秒发出一次 <- 这表明连接肯定是有效的。然后它使用 sockets.emit 来接收一个数据数组,这个函数。不是简单的按钮按下的部分无法实现任何目标(请参阅 React 元素底部的两个“保存更改”按钮)。没有错误,没有响应,根本没有确认。我已经在它自己的功能中尝试过内联。完全相同的服务器路由可以同时运行具有类组件的单独应用程序。
帮助将不胜感激。无论如何这里有一些代码..
import React, { Component,useState, useEffect } from "react";
import io from "socket.io-client";
import './Secret.css'
const Secret = () => {
const [time, setTime] = useState('');
const [userlist, setUserlist] = useState([]);
const socketUrl = 'http://localhost:3001';
let socket = io(socketUrl, {
autoConnect: false,
});
useEffect(() => {
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'React …Run Code Online (Sandbox Code Playgroud)