Home

Issue: 3012

Using express-sessions in Nuxt

[issue link]

Hey,

I’m planning to use sessions in my Nuxt application instead of relying on cookies for data storage.

Here’s my code (plugin/express-sessions.js)

import Vue from 'vue'
let Session = require('express-session')

var sessionConfig = {
  secret: 'asdnsadnda',
  resave: 'false',
  saveUninitialized: 'false'
}

Vue.use(Session(sessionConfig))

here are my actions (store/index.js)

const actions = {
  nuxtServerInit ({ commit }, { req }) {
    console.log(req.session)
    if (req.session && req.session.authUser) {
      commit('SET_USER', req.session.authUser)
    }
  },

  login ({ req }, { commit }, payload) {
    req.session.authUser = payload.user
    commit('SET_USER', payload.user)
  }

}

here’s my nuxt.config.js

plugins: [
    '~/plugins/vuetify.js',
    '~/plugins/express-sessions.js'
],
 build: {
    vendor: [
      '~/plugins/vuetify.js',
      'express-session',
      'babel-polyfill'
    ]
...

Here’s what I’m facing now:
image

Any ideas what might be wrong?

Please help me!

This question is available on Nuxt.js community (#c2609)