Authentication for Nextra Doc Theme #2446
Replies: 4 comments 1 reply
-
You can use Next.js middleware to add authentication to your Nextra project with Next Auth: /*
* This file is responsbile for all the auth magic for the documentation.
* It ensures that the user has a session before we show them anything on the page.
*
* This is all done server-side.
*
* Useful links:
* @see https://nextjs.org/docs/app/building-your-application/routing/middleware
* @see https://next-auth.js.org/configuration/nextjs#basic-usage
*/
import { withAuth } from 'next-auth/middleware';
export default withAuth({
callbacks: {
authorized({ token }) {
// If we are in dev mode, don't require auth.
if (process.env.NODE_ENV === 'development') return true;
// If there is a session token, allow login
if (token) return true;
// By default, don't allow login.
return false;
},
},
}); |
Beta Was this translation helpful? Give feedback.
-
You can find an example of nextra with authentication using Suggestion of how to improve it are welcome! |
Beta Was this translation helpful? Give feedback.
-
Just to clarify a doubt I have, this will also work for partial routes and not only for entire app? Example let's say I have 10 routes (or 10 pages) and I want to keep 5 of those routes public and rest 5 as private. Can anyone please clarify this? |
Beta Was this translation helpful? Give feedback.
-
HI,
Is it possible to apply authentication to doc theme? If so, could anyone please instruct me on how to add any of the authentication services (Next Auth / AWS Cognito / Clerk / etc.,)
Thank You!!
Beta Was this translation helpful? Give feedback.
All reactions