-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctx.session.isNew undefined #165
Comments
@fengyuanzemin the code you posted here works fine. I suspect that the middleware that threw the error The following will not work as expected. const sessions = {}
const CONFIG = {
store: {
async get(key) {
return sessions[key]
}
, async set(key, value) {
sessions[key] = value
}
, async destroy(key) {
sessions[key] = null
}
}
}
app.use(async context => {
console.log(context.session)
})
app.use(session(CONFIG, app)) You must use the session middleware first. app.use(session(CONFIG, app))
app.use(async (context, next) => {
console.log(context.session)
}) |
I have the same "issue". import Koa from 'koa'
import BodyParser from 'koa-bodyparser'
const cors = require('@koa/cors')
const bodyParser = require('koa-bodyparser')
const session = require('koa-session')
const app = new Koa()
app.use(cors({
credentials: true
}))
app.use(bodyParser())
app.keys = ['somekey']
app.use(session(app))
app.use(ctx => {
console.log(ctx.session.isNew)
ctx.session.foo = 'bar'
ctx.status = 200
})
const port = 3000
app
.use(BodyParser())
.listen(port)
.on('listening', () => {
console.log(`Listening on port ${port}...`)
}) I have a client-side app on port 8080, sending POST requests with axios. import axios from 'axios'
export const http = axios.create({
withCredentials: true,
baseURL: 'http://localhost:3000'
}) |
Example
dependencies
index.js
The text was updated successfully, but these errors were encountered: