2017-09-04 60 views
1

感謝您的關注。這是我得到的語法錯誤:意外的令牌語法錯誤我看不到

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

我真的很感激任何輸入。

+2

您的服務器是否完全支持ESnext? (特別是異步等待..) –

+0

@Jonasw可能是正確的。你有一個webpack配置文件或babelrc設置? – sourRaspberri

+0

@sourRasperri webpack?這是什麼與服務器端代碼的待辦事項?爲什麼要一個babel,如果你只是更新bodejs? –

回答

0

對於較新的ES6語法,節點只是未正確更新。更新它解決了這個問題。感謝您的幫助。