#how to secure urls

1 messages · Page 1 of 1 (latest)

deep tulip
#

What are the ways to secure particular routes in nextjs? Answer for both pages and app router.

maiden terraceBOT
#

Hi @deep tulip. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Next.js, securing URLs or routes can be achieved through authentication and authorization. Authentication verifies who a user is, while authorization controls what a user can access. Next.js supports multiple authentication patterns, each designed for different use cases.

For the Pages Router, you can use the following authentication patterns:

For the App Router, there are several common authentication solutions that support it:

Remember, the App Router takes priority over the Pages Router. Routes across directories should not resolve to the same URL path and will cause a build-time error to prevent a conflict.

For more information, you can refer to the Next.js documentation on authentication (https://nextjs.org/docs/pages/building-your-application/routing/authenticating) and the Next.js documentation on the App Router (https://nextjs.org/docs/app).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: