Next.js Discord

Discord Forum

state management in middleware

Unanswered
Nile tilapia posted this in #help-forum
Open in Discord
Nile tilapiaOP
I'm using custom server(express) with Next.js 14 (app router)
to handle auth in frontend i have to call backend api on every route change to validate token in nextjs middleware
is there any other option to handle auth state in nextjs that can be accessed in middleware (like useContext api)?

1 Reply

@Nile tilapia I'm using custom server(express) with Next.js 14 (app router) to handle auth in frontend i have to call backend api on every route change to validate token in nextjs middleware is there any other option to handle auth state in nextjs that can be accessed in middleware (like useContext api)?
I handle my authentication without using an express server. You can make rest calls inside of the middleware, create a auth/validate enpoint and hit it and make sure its still valid there.