启动我的应用程序时出现一些错误:
/api # yarn start
yarn run v1.21.1
$ nodemon server-express.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server-express.js`
/api/node_modules/passport-oauth2/lib/strategy.js:86
if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); }
^
TypeError: OAuth2Strategy requires a clientID option
at Strategy.OAuth2Strategy (/api/node_modules/passport-oauth2/lib/strategy.js:86:34)
at new Strategy (/api/node_modules/passport-google-oauth20/lib/strategy.js:52:18)
at Object.<anonymous> (/api/helpers/authHelper.js:26:5)
at Module._compile (internal/modules/cjs/loader.js:1139:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
at Module.load (internal/modules/cjs/loader.js:988:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Module.require (internal/modules/cjs/loader.js:1028:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/api/server-express.js:13:23)
at Module._compile (internal/modules/cjs/loader.js:1139:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
at Module.load (internal/modules/cjs/loader.js:988:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...
这是我需要的.env文件ID:
# NODE TODO
NODE_ENV=production
PORT=3001
HOST=localhost
# MONGO TODO
MONGO_USER=...
MONGO_DB=....
MONGO_PASS=....
MONGO_HOST=localhost
#GOOGLE_AUTH TODO
GOOGLE_CLIENTID = "....-......apps.googleusercontent.com"
GOOGLE_CLIENTSECRET = ".....-....."
GOOGLE_REDIRECT = "http://localhost:3001/auth/google/callback"
#FACEBOOK_AUTH TODO
FACEBOOK_CLIENTID = ....
FACEBOOK_CLIENTSECRET = "....."
FACEBOOK_CALLBACKURL = "http://localhost:3001/auth/facebook/callback"
FACEBOOK_TEST_EMAIL = "s....@gmail.com"
#LOCAL_URL TODO
CLIENT = "localhost:3000"
CLIENTURL = "http://localhost:3000"
SCHEMES = "http://"
SERVERAPI = "http://localhost:3001"
#GMAIL
SECRETKEY = ".....="
GMAILPSW = "....!"
SUPPORTEMAIL = "...@gmail.com"
#JWT
JWTSECRET = "...."
#COOKIE
COOKIEKEY = "...."
您能帮我解决这个问题吗,我真的不知道错误来自哪里
谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢
答案 0 :(得分:0)
您需要转到
https://console.developers.google.com/
在这里您需要设置您的应用程序。启用Google API,然后搜索Google+,然后按启用API。然后创建api凭据。 完成后,您将获得clientId和SecretId。
设置您的password.js文件时,您必须将这些凭据传递给Google策略。为了安全起见,请将这些凭据放入您应用中的其他文件中,然后将其导入。
module.exports = {
googleClientID:
"mygooogleclientIdHERE.apps.googleusercontent.com",
googleClientSecret: "secretIdHERE"
};
在wallet.js中
const keys = require("../config/keys.js");
const passport = require("passport");
passport.use(
new GoogleStrategy(
{
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: "/auth/google/callback"
},
(accessToken, refreshToken, profile, done) => {
//this is where you implement the communication between server and database
}
)
);