rsnext/examples/auth-with-stytch
leung018 66597be8a7
Add .yarn/install-state.gz to .gitignore (#56637)
### Reason for making this change
https://yarnpkg.com/getting-started/qa#:~:text=yarn%2Finstall%2Dstate.,your%20workspaces%20all%20over%20again.
In the official documentation of `yarn`, it is stated that `.yarn/install-state.gz` is an optimization file that developer shouldn't ever have to commit. However, currently, when running `create-next-app`, `.yarn/install-state.gz` is being commited.

### Remaining work
I apologize for only modifying one template initially to initiate the discussion first.

If this change is agreed upon,  it should be synchronized with other `.gitignore` templates. Would it be possible to follow a similar approach as in https://github.com/vercel/next.js/pull/47241? I would appreciate any assistance in syncing this change.
2023-10-18 16:34:48 +00:00
..
components Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00
lib Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00
pages [Docs] Update examples to favour functional _document (#39871) 2022-08-23 18:52:31 +00:00
public Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00
styles Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00
.env.template Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00
.gitignore Add .yarn/install-state.gz to .gitignore (#56637) 2023-10-18 16:34:48 +00:00
next-env.d.ts Remove incorrect entries for pnpm debug log (#47241) 2023-03-26 22:26:05 -07:00
package.json BREAKING CHANGE: Remove React 17 (#41629) 2022-10-21 22:20:36 +00:00
README.md fix typos (#56870) 2023-10-18 00:46:47 +00:00
tsconfig.json Add authentication example using Stytch (#32194) 2021-12-22 19:30:44 +00:00

Stytch + Next.js example app on Vercel

This is a Stytch + Next.js project that showcases how to enable elegant authentication in your application.

stytch

In this repo, we have two sample auth flows:

  • SDK integration: This flow uses Stytch's React component to create a login and sign-up flow using Email Magic Links.
  • API integration: This flow uses a custom UI with Stytch's backend API for Onetime Passcodes(OTP) via SMS authentication.

Both flows use Stytch's Node client library and iron-session for session management.

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, 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 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.

Deploy on Vercel

Setting up Stytch

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 section of your Dashboard. Add https://*.vercel.app:3000 as both a login and sign-up redirect URL.

Running the example app

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 for pointers on filling in the appropriate environment variables for this step.

Deploy with Vercel

Running locally via vercel dev

Setting up Stytch

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.

Once you've gathered these values, add them to a new .env.local file. Example:

cp .env.template .env.local
# Replace your keys in new .env.local file

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 section of your Dashboard. Add http://localhost:3000/api/authenticate_magic_link as both a login and sign-up redirect URL.

Running the example app

Install dependencies by running

npm install
# or
yarn install

You can then run a development server using:

vercel dev

Open http://localhost:3000 with your browser to see the result.

Documentation

Learn more about some of Stytch's products used in this example app: