|
| 1 | +> The example repository is maintained from a [monorepo](https://github.com/nextauthjs/next-auth/tree/main/apps/examples/nextjs). Pull Requests should be opened against [`nextauthjs/next-auth`](https://github.com/nextauthjs/next-auth). |
| 2 | +
|
| 3 | +<p align="center"> |
| 4 | + <br/> |
| 5 | + <a href="https://authjs.dev" target="_blank"><img width="150px" src="https://authjs.dev/img/logo-sm.png" /></a> |
| 6 | + <h3 align="center">NextAuth.js Example App</h3> |
| 7 | + <p align="center"> |
| 8 | + Open Source. Full Stack. Own Your Data. |
| 9 | + </p> |
| 10 | + <p align="center" style="align: center;"> |
| 11 | + <a href="https://npm.im/next-auth"> |
| 12 | + <img alt="npm" src="https://img.shields.io/npm/v/next-auth?color=green&label=next-auth"> |
| 13 | + </a> |
| 14 | + <a href="https://bundlephobia.com/result?p=next-auth-example"> |
| 15 | + <img src="https://img.shields.io/bundlephobia/minzip/next-auth?label=next-auth" alt="Bundle Size"/> |
| 16 | + </a> |
| 17 | + <a href="https://www.npmtrends.com/next-auth"> |
| 18 | + <img src="https://img.shields.io/npm/dm/next-auth?label=next-auth%20downloads" alt="Downloads" /> |
| 19 | + </a> |
| 20 | + <a href="https://npm.im/next-auth"> |
| 21 | + <img src="https://img.shields.io/badge/npm-TypeScript-blue" alt="TypeScript" /> |
| 22 | + </a> |
| 23 | + </p> |
| 24 | +</p> |
| 25 | + |
| 26 | +## Overview |
| 27 | + |
| 28 | +NextAuth.js is a complete open source authentication solution. |
| 29 | + |
| 30 | +This is an example application that shows how `next-auth` is applied to a basic Next.js app. |
| 31 | + |
| 32 | +The deployed version can be found at [`next-auth-example.vercel.app`](https://next-auth-example.vercel.app) |
| 33 | + |
| 34 | +### About NextAuth.js |
| 35 | + |
| 36 | +NextAuth.js is an easy to implement, full-stack (client/server) open source authentication library originally designed for [Next.js](https://nextjs.org) and [Serverless](https://vercel.com). Our goal is to [support even more frameworks](https://github.com/nextauthjs/next-auth/issues/2294) in the future. |
| 37 | + |
| 38 | +Go to [next-auth.js.org](https://authjs.dev) for more information and documentation. |
| 39 | + |
| 40 | +> _NextAuth.js is not officially associated with Vercel or Next.js._ |
| 41 | +
|
| 42 | +## Getting Started |
| 43 | + |
| 44 | +### 1. Clone the repository and install dependencies |
| 45 | + |
| 46 | +``` |
| 47 | +git clone https://github.com/nextauthjs/next-auth-example.git |
| 48 | +cd next-auth-example |
| 49 | +npm install |
| 50 | +``` |
| 51 | + |
| 52 | +### 2. Configure your local environment |
| 53 | + |
| 54 | +Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git): |
| 55 | + |
| 56 | +``` |
| 57 | +cp .env.local.example .env.local |
| 58 | +``` |
| 59 | + |
| 60 | +Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc). |
| 61 | + |
| 62 | +#### Database |
| 63 | + |
| 64 | +A database is needed to persist user accounts and to support email sign in. However, you can still use NextAuth.js for authentication without a database by using OAuth for authentication. If you do not specify a database, [JSON Web Tokens](https://jwt.io/introduction) will be enabled by default. |
| 65 | + |
| 66 | +You **can** skip configuring a database and come back to it later if you want. |
| 67 | + |
| 68 | +For more information about setting up a database, please check out the following links: |
| 69 | + |
| 70 | +- Docs: [authjs.dev/reference/core/adapters](https://authjs.dev/reference/core/adapters) |
| 71 | + |
| 72 | +### 3. Configure Authentication Providers |
| 73 | + |
| 74 | +1. Review and update options in `auth.ts` as needed. |
| 75 | + |
| 76 | +2. When setting up OAuth, in the developer admin page for each of your OAuth services, you should configure the callback URL to use a callback path of `{server}/api/auth/callback/{provider}`. |
| 77 | + |
| 78 | +e.g. For Google OAuth you would use: `http://localhost:3000/api/auth/callback/google` |
| 79 | + |
| 80 | +A list of configured providers and their callback URLs is available from the endpoint `api/auth/providers`. You can find more information at https://authjs.dev/getting-started/providers/oauth-tutorial |
| 81 | + |
| 82 | +1. You can also choose to specify an SMTP server for passwordless sign in via email. |
| 83 | + |
| 84 | +### 4. Start the application |
| 85 | + |
| 86 | +To run your site locally, use: |
| 87 | + |
| 88 | +``` |
| 89 | +npm run dev |
| 90 | +``` |
| 91 | + |
| 92 | +To run it in production mode, use: |
| 93 | + |
| 94 | +``` |
| 95 | +npm run build |
| 96 | +npm run start |
| 97 | +``` |
| 98 | + |
| 99 | +### 5. Preparing for Production |
| 100 | + |
| 101 | +Follow the [Deployment documentation](https://authjs.dev/getting-started/deployment) |
| 102 | + |
| 103 | +## Acknowledgements |
| 104 | + |
| 105 | +<a href="https://vercel.com?utm_source=nextauthjs&utm_campaign=oss"> |
| 106 | +<img width="170px" src="https://raw.githubusercontent.com/nextauthjs/next-auth/main/docs/static/img/powered-by-vercel.svg" alt="Powered By Vercel" /> |
| 107 | +</a> |
| 108 | +<p align="left">Thanks to Vercel sponsoring this project by allowing it to be deployed for free for the entire NextAuth.js Team</p> |
| 109 | + |
| 110 | +## License |
| 111 | + |
| 112 | +ISC |
0 commit comments