hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.63k stars 65 forks source link

Render a page back to client #139

Closed maxy4u closed 2 years ago

maxy4u commented 3 years ago

Hi, This is more of a question and not an issue. I am trying to build one logic to redirect to 401.js page in next js from our api if user is not authenticated. I know we can do res.status 302 and then location param will redirect. However, the status code 30* will not do justice to 401 page. Is there a way to render a page back to client like in express we have render method ?

Thanks in advance. Regards Gaurav

hoangvvo commented 3 years ago

You can try to make use of app.render from https://nextjs.org/docs/advanced-features/custom-server but I have not tried it yet.