我在 localhost:3000 有一个 React 客户端设置,在 localhost:5000 有一个 node.js 服务器
我正在尝试一个简单的身份验证流程,其中客户端尝试使用 Passport.js Google OAuth2.0 与服务器进行身份验证,并使用带有 MongoDB 存储的快速会话保持身份验证。
我相信我发现 req.user 未定义的原因是因为我缺乏对 auth 流程应该如何工作以及实际代码的任何问题的理解。
我正在通过反应客户端中的以下代码启动身份验证流程:
<Button href="http://localhost:5000/auth/google">
Login using Google
</Button>
Run Code Online (Sandbox Code Playgroud)
以下是我的auth.js文件:
const express = require("express");
const passport = require("passport");
const router = express.Router();
// @desc Auth with Google
// @route GET /auth/google
router.get("/google", passport.authenticate("google", { scope: ["profile"] }));
// @desc Google auth callback
// @route GET /auth/google/callback
router.get(
"/google/callback",
passport.authenticate("google", {
failureRedirect: "/",
successRedirect: "http://localhost:3000/dashboard",
})
);
// @desc Logout …Run Code Online (Sandbox Code Playgroud) 每当我尝试启动firebase时,总会出现这些错误
W/GooglePlayServicesUtil: Google Play services out of date. Requires 11020000 but found 8489470
W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
E/FA: Discarding data. Failed to send app launch
E/FA: Failed to get app instance id
E/FA: Failed to send current screen to service
E/FA: Discarding data. Failed to send event to service
Run Code Online (Sandbox Code Playgroud)
我得到的是与Google Play服务相关的内容,但我无法弄清楚如何修复它,我正在运行Android Studio 2.1.2并且SDK中没有Google Play服务的更新
编辑:我的应用程序Gradle(我正在使用模拟器)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.sc.voxcinemascamp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
} …Run Code Online (Sandbox Code Playgroud)