Giter Site home page Giter Site logo

dsstewa / stytch-nextjs-integration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stytchauth/stytch-nextjs-integration

0.0 0.0 0.0 2.15 MB

Stytch demo application built on Next.js

Home Page: https://www.stytchdemo.com/

License: MIT License

JavaScript 0.51% TypeScript 95.23% CSS 4.26%

stytch-nextjs-integration's Introduction

Stytch + Next.js Example App

This is a Stytch + Next.js project bootstrapped with create-next-app. Check out a live version of this site here.

stytch

In this repo, we have three sample auth flows:

  • SDK with React component: This flow uses Stytch's React component to create a login and sign-up flow using Email magic links and OAuth logins.
  • SDK with custom UI: This flow uses a custom UI with Stytch's headless SDK to implement Onetime Passcodes(OTP) via SMS authentication.
  • Direct API: This flow uses a custom UI with Stytch's backend API for a two step authenticaiton which requires Email magic links and WebAuthn.

Note: By default this example app enables five of our OAuth providers, Google, Microsoft, Facebook, Github, 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 components/LoginWithReactSDK.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.

Running with Vercel

If you'd like to run this example app with Vercel, 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/authenticate as both a login and sign-up redirect URL. If you'd like to try our WebAuthn example integration, add https://*.vercel.app/api/authenticate_magic_link_with_webauthn as a login and sign-up redirect URL as well.

Additionally, you will need to configure the headless SDK settings. In your SDK Configuration add https://*.vercel.app as an authorized domain and toggle on the Auth methods "Email magic links", "OAuth", and "SMS passcodes (OTP)".

Note: To use Google One Tap in this example app, you'll need to deploy on Vercel first, then add the resulting URL, e.g. https://<uuid>.vercel.app/ as both a Stytch Redirect URL and as a Authorized JavaScript origins in your Google OAuth dashboard.

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

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/authenticate as both a login and sign-up redirect URL. If you'd like to try our WebAuthn example integration, add http://localhost:3000/api/authenticate_magic_link_with_webauthn as a login and sign-up redirect URL as well.

Running the example app

Install dependencies by running

npm install
# or
yarn install

You can then run a development server using:

npm run dev
# or
yarn 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:

stytch-nextjs-integration's People

Contributors

cal-stytch avatar snyk-bot avatar chris-stytch avatar allison-stytch avatar julianna-stytch avatar dependabot[bot] avatar nathan-stytch avatar max-stytch avatar edwin-stytch avatar ci-stytch avatar kaden-stytch avatar lucy-stytch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.