|
| 1 | +# Stytch + Next.js example app on Vercel |
| 2 | + |
| 3 | +This is a [Stytch](https://stytch.com) + [Next.js](https://nextjs.org/) project that showcases how to enable elegant authentication in your applicaiton. |
| 4 | + |
| 5 | +<p align="center"><img src="./public/example-app-image.png" alt="stytch" width="50%"/></p> |
| 6 | + |
| 7 | +In this repo, we have two sample auth flows: |
| 8 | + |
| 9 | +- SDK integration: This flow uses Stytch's React component to create a login and sign-up flow using [Email Magic Links](https://stytch.com/docs/api/send-by-email). |
| 10 | +- API integration: This flow uses a custom UI with Stytch's backend API for [Onetime Passcodes(OTP) via SMS](https://stytch.com/docs/api/sms-otp-overview) authentication. |
| 11 | + |
| 12 | +Both flows use Stytch's [Node client library](https://github.com/stytchauth/stytch-node) and [`iron-session`](https://github.com/vvo/next-iron-session) for session management. |
| 13 | + |
| 14 | +**Note:** By default this example app enables three of our OAuth providers, Google, Microsoft, and Apple. If you haven't set up these OAuth providers in your [Dashboard](https://stytch.com/dashboard/oauth), you'll receive a redirect error when you attempt to login via those providers. You may remove all OAuth methods by removing `SDKProductTypes.oauth` from the `products` array in [pages/index.tsx](pages/index.tsx) or adjust which ones are displayed by via `oauthOptions.providers` in the same file. More detail on working with OAuth providers in our SDK may be found in our [Docs](https://stytch.com/docs/javascript-sdk#javascript-sdk/oauth). |
| 15 | + |
| 16 | +# Deploy on Vercel |
| 17 | + |
| 18 | +## Setting up Stytch |
| 19 | + |
| 20 | +The first step is to configure the appropriate redirect URLs for your project. You'll set these magic link redirect URLs in the [Redirect URLs](https://stytch.com/dashboard/redirect-urls) section of your Dashboard. Add `https://*.vercel.app:3000` as both a login and sign-up redirect URL. |
| 21 | + |
| 22 | +## Running the example app |
| 23 | + |
| 24 | +Now just click the deploy button below! Once you're signed in to your Vercel account, you'll be guided through how to get up and running quickly. Check out [.env.template](/.env.template) for pointers on filling in the appropriate environment variables for this step. |
| 25 | + |
| 26 | +[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch%2F&env=STYTCH_PROJECT_ENV,STYTCH_PROJECT_ID,STYTCH_SECRET,NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN,IRON_SESSION_PASSWORD,IRON_SESSION_COOKIE_NAME&envDescription=All%20variables%20here%20need%20values%2C%20see%20the%20following%20link%20for%20pointers%20on%20how%20to%20feel%20these%20out.&envLink=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch%2F.env.template&project-name=stytch-nextjs-vercel&repo-name=stytch-nextjs-vercel&demo-title=Stytch%20on%20Next.js%20with%20Vercel&demo-description=Next.js%20example%20app%20using%20Stytch%20authentication&demo-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Fblob%2Fcanary%2Fexamples%2Fauth-with-stytch&demo-image=https%3A%2F%2Fstytch.com%2Flogo-preview.png) |
| 27 | + |
| 28 | +# Running locally via `vercel dev` |
| 29 | + |
| 30 | +## Setting up Stytch |
| 31 | + |
| 32 | +After signing up for Stytch, you'll need your Project's `project_id`, `secret`, and `public_token`. You can find these in the [API keys tab](https://stytch.com/dashboard/api-keys). |
| 33 | + |
| 34 | +Once you've gathered these values, add them to a new .env.local file. |
| 35 | +Example: |
| 36 | + |
| 37 | +```bash |
| 38 | +cp .env.template .env.local |
| 39 | +# Replace your keys in new .env.local file |
| 40 | +``` |
| 41 | + |
| 42 | +Next we'll configure the appropriate redirect URLs for your project, you'll set these magic link URLs for your project in the [Redirect URLs](https://stytch.com/dashboard/redirect-urls) section of your Dashboard. Add `http://localhost:3000/api/authenticate_magic_link` as both a login and sign-up redirect URL. |
| 43 | + |
| 44 | +## Running the example app |
| 45 | + |
| 46 | +Install dependencies by running |
| 47 | + |
| 48 | +```bash |
| 49 | +npm install |
| 50 | +# or |
| 51 | +yarn install |
| 52 | +``` |
| 53 | + |
| 54 | +You can then run a development server using: |
| 55 | + |
| 56 | +```bash |
| 57 | +vercel dev |
| 58 | +``` |
| 59 | + |
| 60 | +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 61 | + |
| 62 | +## Documentation |
| 63 | + |
| 64 | +Learn more about some of Stytch's products used in this example app: |
| 65 | + |
| 66 | +- [Stytch React](https://www.npmjs.com/package/@stytch/stytch-react) |
| 67 | +- [Stytch's node client library](https://www.npmjs.com/package/stytch) |
| 68 | +- [iron-session](https://github.com/vvo/next-iron-session) |
0 commit comments