express session with cookie parser
Thanks to: https://medium.com/developer-rants/session-cookies-between-express-js-and-vue-js-with-axios-98a10274fae7
npm i cookie-parser express-session cors
import * as cookieParser from 'cookie-parser';
import * as session from 'express-session';
import * as cors from 'cors';
// Populate req.cookies
this.express.use(cookieParser());// Session setup
this.express.use(session({
secret: 'wow very secret',
cookie: {
maxAge: 600000,
secure: true
},
saveUninitialized: false,
resave: false,
unset: 'destroy'
}));this.express.use(cors({
origin: [
'http://localhost:8080',
'https://localhost:8080'
],
credentials: true,
exposedHeaders: ['set-cookie']
}));import axios from 'axios';
import VueAxios from 'vue-axios';axios.defaults.withCredentials = true;
Vue.use(VueAxios, axios);
Vue.axios.post(
'http://my.server.com/',
{
data: 'some post data'
},
{
withCredentials: false
})
req.session.destroy();
Comments
Post a Comment