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

228
Views
How to check the jwt and next-auth in the same midellware in next js

I have an application with next-auth and a simple login with jwt but when i use the middleware in next js to check the next-auth's session is exists , but what if the user log in with the simple login (username & pwd ) , i try to store my jwt from the simple login in cookies but the middleware is in the backend and it can't connect to the frontend , here is my middleware

import {NextResponse} from "next/server";

export async function middleware(req) {

        let token = await getToken({req,secret: process.env.NEXTAUTH_SECRET})

        let {pathname}  = req.nextUrl;
        
        if(pathname.includes("/api/auth") || token) return NextResponse.next();
        
        if( !token && pathname !== "/login") return NextResponse.redirect(`${process.env.NEXTAUTH_URL}/login`); // if there is no jwt or token or the user not comming from /login then redirect him to /login

}

How can i check the jwt token from the simple log in and the token from next-auth in the same middleware because when i try to log in with the simple it's not redirect me to the the homeenter image description here

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!