title | description | tags | ||||
---|---|---|---|---|---|---|
NextJS Auth |
A NextJS app using NextAuth.js for authentication with a MongoDB database |
|
The example is a NextJS app with authentication using NextAuth.js.
It uses MongoDB to persist user accounts and support email sign in. Adding additional providers is as simple as commenting them out from /pages/api/auth/[...nextauth].js
.
- NextJS
- NextAuth.js
- MongoDB
- Click the
Deploy on Railway
button above - Add the required environment variables (
SECRET
,EMAIL_SERVER
)- The
EMAIL_SERVER
has to be a connection string in this format -smtp://username:password@smtp.example.com:587
- The
- Clone the project locally
- Install dependencies -
yarn
- Connect to your Railway project -
railway link
- Start the development server
railway run yarn dev
- The value for
NEXTAUTH_URL
is set tohttp://localhost:3000
for ease of use. You must update it before deploying to production. - You can read more about how the email provider works here.
- You can read more about how objects are stored in the database here.
- If you want to configure additional providers, you can do so using the information mentioned here.