   morgan = require 'morgan'
   app.use morgan 'dev'
 
-app.use express.static __dirname + '/public'
-app.use session secret: 'secret-TODO-change-me'
-app.use body_parser.json()
-app.use body_parser.urlencoded extended: true
-
+passport.serializeUser   (user, done) -> done null, user
+passport.deserializeUser ( obj, done) -> done null, obj
 passport.use new (require('passport-google-openidconnect').Strategy)
     clientID:     config.google.client_id
     clientSecret: config.google.client_secret
     callbackURL:  "http://127.0.0.1:3000/auth/google/return"
   , (iss, sub, profile, accessToken, refreshToken, done) ->
-    profile.accessToken = accessToken
     done(null, profile)
 
+app.use express.static __dirname + '/public'
+app.use session secret: 'secret-TODO-change-me'
+app.use body_parser.json()
+app.use body_parser.urlencoded extended: true
 app.use passport.initialize()
 app.use passport.session()
 


  console.log 'Started jachi-koro %s', port

app.get '/auth/google', passport.authenticate('google-openidconnect')

app.get '/auth/google/return',
  passport.authenticate('google-openidconnect', { failureRedirect: '/login' }),
  (req, res) ->
    res.redirect '/'

app.get '/api/session/user', (req, res) ->
  sess = req.session

  if sess.user
    res.json sess.user
  else
    res.status(400).send 'No active session'


body_parser = require 'body-parser'
passport    = require 'passport'
config      = require(__dirname + '/../config')

app = express()

