【发布时间】:2018-02-12 20:39:04
【问题描述】:
感谢您的观看。这是我得到的语法错误:
[0] /Users/alexkarasik/Documents/server/services/passport.js:26
[0] async (accessToken, refreshToken, profile, done) => {
[0] ^
[0] SyntaxError: Unexpected token (
这是错误引用的文件。我已经上下查找了 2 多个小时,并且认为没有理由收到此错误:
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const mongoose = require('mongoose');
const keys = require('../config/keys');
const User = mongoose.model('users');
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
User.findById(id)
.then(user => {
done(null, user);
})
});
passport.use(
new GoogleStrategy({
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: '/auth/google/callback',
proxy: true
},
async (accessToken, refreshToken, profile, done) => {
const existingUser = await User.findOne({ googleId: profile.id });
if (existingUser){
//we already have a record with the give profileId
return done(null, existingUser);
}
// we don't have a user record with this ID, make a new record
const user = await new User({ googleId: profile.id }).save();
done(null, user);
}
)
);
非常感谢任何意见。
【问题讨论】:
-
您的服务器是否完全支持 ESnext? (尤其是异步等待..)
-
@Jonasw 可能是对的。你有 webpack 配置文件或 babelrc 设置吗?
-
@sourRasperri webpack?这与服务器端代码有什么关系?如果你可以简单地更新 bodejs,为什么还要一个 babel?
-
您可以使用类似这样的方式返回到 Promise 处理:
(accessToken, refreshToken, profile, done) => { User.findOne({ googleId : profile.id }).exec().then( (existingUser)=>{ /* [...] */ } ); } -
你在什么环境下尝试运行这段代码,究竟是什么引发了这个错误?
标签: javascript syntax-error react-server