|
| 1 | +> The example repository is maintained from a [monorepo](https://github.com/nextauthjs/next-auth/tree/main/apps/examples/express). 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"> |
| 6 | + <img height="64" src="https://authjs.dev/img/logo/logo-sm.png" /> |
| 7 | + </a> |
| 8 | + <a href="https://expressjs.com" target="_blank"> |
| 9 | + <img height="64" src="https://i.cloudup.com/zfY6lL7eFa-3000x3000.png" /> |
| 10 | + </a> |
| 11 | + <h3 align="center"><b>Express Auth</b> - Example App</h3> |
| 12 | + <p align="center"> |
| 13 | + Open Source. Full Stack. Own Your Data. |
| 14 | + </p> |
| 15 | + <p align="center" style="align: center;"> |
| 16 | + <a href="https://npm.im/@auth/express"> |
| 17 | + <img alt="npm" src="https://img.shields.io/npm/v/@auth/express?color=green&label=@auth/express&style=flat-square"> |
| 18 | + </a> |
| 19 | + <a href="https://bundlephobia.com/result?p=@auth/express"> |
| 20 | + <img src="https://img.shields.io/bundlephobia/minzip/@auth/express?label=size&style=flat-square" alt="Bundle Size"/> |
| 21 | + </a> |
| 22 | + <a href="https://www.npmtrends.com/@auth/express"> |
| 23 | + <img src="https://img.shields.io/npm/dm/@auth/express?label=downloads&style=flat-square" alt="Downloads" /> |
| 24 | + </a> |
| 25 | + <a href="https://npm.im/@auth/express"> |
| 26 | + <img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" /> |
| 27 | + </a> |
| 28 | + </p> |
| 29 | +</p> |
| 30 | + |
| 31 | +## Overview |
| 32 | + |
| 33 | +This is the official Express Auth example for [Auth.js](https://express.authjs.dev). |
| 34 | + |
| 35 | +## Getting started |
| 36 | + |
| 37 | +You can instantly deploy this example to [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=express-auth-example) by clicking the following button. |
| 38 | + |
| 39 | +[](https://vercel.com/new/git/external?repository-url=https://github.com/nextauthjs/express-auth-example&project-name=express-auth-example&repository-name=express-auth-example) |
| 40 | + |
| 41 | +## Environment Variables |
| 42 | + |
| 43 | +Once deployed, kindly ensure you set all [required environment variables](https://authjs.dev/getting-started/deployment#environment-variables) in the `Environment` section of your hosting service. |
| 44 | + |
| 45 | +## Node.js Compatibility |
| 46 | + |
| 47 | +The recommended version of Node.js to use in this example is Node.js v20.0.0. |
| 48 | + |
| 49 | +If you are using a version of Node.js lower than this (for example the minimum supported node version v18.0.0), you may need to enable Web Crypto API via the `--experimental-webcrypto` flag in the `start` and `dev` scripts of your `package.json` file. |
| 50 | + |
| 51 | +Instead of using the experimental flag, you may use the following polyfill: |
| 52 | + |
| 53 | +```ts |
| 54 | +// polyfill.cts |
| 55 | +globalThis.crypto ??= require("crypto").webcrypto |
| 56 | +``` |
| 57 | + |
| 58 | +And then import it within a top-level file in the application: |
| 59 | + |
| 60 | +```ts |
| 61 | +// server.ts |
| 62 | +import "./polyfill.cjs" |
| 63 | +``` |
0 commit comments