When attempting to retrieve sessions, I encounter an issue. Is everything set up correctly in the following main files: server, config?
store/index.js
export const actions = {
nuxtServerInit ({ commit }, { req }) {
console.log(req);
}
The console log displays "undefined" for me.
api/index.js
const express = require('express');
const router = express.Router()
const passport = require('passport');
const twitchStrategy = require("@d-fischer/passport-twitch").Strategy;
const app = express();
app.use(require('cookie-parser')());
app.use(require('express-session')({ secret: "bla-bla-bla", resave: false, saveUninitialized: false }));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new twitchStrategy({
clientID: 'bla-bla-bla',
clientSecret: 'bla-bla-bla',
callbackURL: "bla-bla-bla",
scope: "user_read"
}, (accessToken, refreshToken, profile, done) => {
return done(null, profile);
}
));
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
const user = require('./routes/user');
app.use(user);
router.use((req, res, next) => {
Object.setPrototypeOf(req, app.request)
Object.setPrototypeOf(res, app.response)
req.res = res
res.req = req
next()
})
module.exports = app;
if (require.main === module) {
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log(`API server listening on port ${port}`);
});
}
Omitting the contents of the routes/user file as it seems clear there.
nuxt.config.js
serverMiddleware: {
'/api': '~/api'
}