我看不到意外的令牌语法错误

时间:2017-09-04 15:11:08

标签: javascript syntax-error react-server

谢谢你看看。这是我得到的语法错误:

[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);
    }
  )
);

我真的很感激任何意见。

1 个答案:

答案 0 :(得分:0)

对于较新的ES6语法,节点没有正确更新。更新它解决了这个问题。谢谢您的帮助。