I'm using next js session v4.0.4 client side with middleware and i wanna know how to store user credential in the session in login page my middleware.js :
import { NextRequest, NextResponse } from 'next/server'
import session from 'next-session'
export async function middleware(req, res) {
await session()(req, res)
return NextResponse.next()
}
my session.js
import nextSession from 'next-session'
export const getSession = nextSession()
function withSession(handler) {
return async function handlerWithSession(req, res) {
await getSession(req, res)
return handler(req, res)
}
}
function applySessionOptions(req, res) {
return getSession(req, res)
}
function withSessionOptions(handler) {
return withSession(handler)
}
export { applySessionOptions as applySession }
export { withSessionOptions as withSession }
My login service
import { withSession} from './session'
const handler = async (req, res) => {
try {
req.session.logged = true,
req.session.commit();
} catch (error) {
console.log(error)
}
}
export default withSession(handler)
When i do console.log(req.session) in my login page i find the logged value but when i try to access from another service the req.session i don't find the logged value any help please