Great article and nice clean code. I want to follow your approach but do not get it working with withApiAuthRequired (nextjs-auth0). Could you point me in the right direction? Keep getting the error 'invalid hook call'.
Thanks a lot! nc().use() requires the function arg to be compatible with the props it receives. If you can't make it work out of the box, you may need to wrap it:
Yeah my original code didn't work, that's a good way to put it. I just wouldn't call it router to avoid confusion, because it's just a handler, the router being managed inside Next core :).
import{NextApiRequest,NextApiResponse}from"next";import{withApiAuthRequired}from"@auth0/nextjs-auth0";importncfrom"next-connect";// Secured api endpoint.// Possible synergy between next-connect and withApiAuthRequired from nextjs-auth0.consthandler=withApiAuthRequired(nc<NextApiRequest,NextApiResponse>().get((req:NextApiRequest,res:NextApiResponse)=>{// ...}).post((req:NextApiRequest,res:NextApiResponse)=>{// ...}));exportdefaulthandler;
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article and nice clean code. I want to follow your approach but do not get it working with
withApiAuthRequired
(nextjs-auth0). Could you point me in the right direction? Keep getting the error 'invalid hook call'.Thanks a lot!
nc().use()
requires the function arg to be compatible with the props it receives. If you can't make it work out of the box, you may need to wrap it:Thanks for your help! Below a suggestion from my side to replace
const handler = nc().use(errorHandler)
withconst handler = router()
.Yeah my original code didn't work, that's a good way to put it. I just wouldn't call it router to avoid confusion, because it's just a handler, the router being managed inside Next core :).
Here is my strategy: