Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Next js session version 4 with middleware client side

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!