GitHub - stytchauth/stytch-react-example: Example B2C React application featuring Email Magic Link and Google OAuth authentication powered by Stytch
Skip to content

Example B2C React application featuring Email Magic Link and Google OAuth authentication powered by Stytch

License

Notifications You must be signed in to change notification settings

stytchauth/stytch-react-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stytch B2C React example application

Overview

This example application demonstrates how one may use Stytch within a React application. This project was bootstrapped with Create React App.

This project uses Stytch's React SDK which provides pre-built UI components, useful React hooks, and headless methods to securely interact with Stytch.

This application features Email Magic Links. You can use this application's source code as a learning resource, or use it as a jumping off point for your own project. We are excited to see what you build with Stytch!

Set up

Follow the steps below to get this application fully functional and running using your own Stytch credentials.

In the Stytch Dashboard

  1. Create a Stytch account. Once your account is set up a Project called "My first project" will be automatically created for you.

  2. Within your new Project, navigate to SDK configuration, and make the following changes:

    • Click Enable SDK.

    • Under Authorized environments add the domain http://localhost:3000.

      Authorized environments
  3. Navigate to Redirect URLs, and add http://localhost:3000/authenticate as the types Login and Sign-up.

    Redirect URLs
  4. Finally, navigate to API Keys, and copy your public_token. You will need this value later on.

On your machine

In your terminal clone the project and install dependencies:

git clone https://github.com/stytchauth/stytch-react-example.git
cd stytch-react-example
npm i

Next, create .env.local file by running the command below and your public_token. Learn more about Create React App's support for custom environment variables here.

echo "REACT_APP_STYTCH_PUBLIC_TOKEN=YOUR_TOKEN_HERE" > .env.local
# For example, echo "REACT_APP_STYTCH_PUBLIC_TOKEN=public-token-test-123abcd-1234-1234-abcd-123123abcabc" > .env.local

Running locally

After completing all the set up steps above the application can be run with the command:

npm start

The application will be available at http://localhost:3000.

You'll be able to login with Email Magic Links and see your Stytch User object, Stytch Session, and see how logging out works.

Next steps

This example app showcases a small portion of what you can accomplish with Stytch. Here are a few ideas to explore:

  1. Add additional login methods like Passwords.
  2. Replace the prebuilt UI with your own using by using the SDK's headless methods.
  3. Add a Google OAuth button, or replace it with the high converting Google One Tap UI.
  4. Secure your app further by building MFA authentication using methods like Passkeys.
  5. Use Stytch Sessions to secure your backend.

Get help and join the community

💬 Stytch community Slack

Join the discussion, ask questions, and suggest new features in our ​Slack community!

❓ Need support?

Check out the Stytch Forum or email us at support@stytch.com.

About

Example B2C React application featuring Email Magic Link and Google OAuth authentication powered by Stytch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published