This example application demonstrates how one may use Stytch within a React application. The project now uses Vite for development and building the application.
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 and OAuth. 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!
This app also implements an authorization page for Stytch Connected Apps, which hosts the IdentityProvider component (related guide in Stytch docs is here). If you're just here to learn about Stytch with React, ignore components/Authorize.js.
Install the Stytch MCP Server and instruct coding agents to follow the steps in Agents.md.
Follow the steps below to get this application fully functional and running using your own Stytch credentials.
-
Create a Stytch account. Once your account is set up a Project called "My first project" will be automatically created for you.
-
Within your new Project, navigate to SDK configuration, and make the following changes:
-
Navigate to Redirect URLs, and add
http://localhost:3000/authenticateas the types Login and Sign-up.
-
Finally, navigate to API Keys, and copy your
public_token. You will need this value later on.
In your terminal clone the project and install dependencies:
git clone https://github.com/stytchauth/stytch-react-example.git
cd stytch-react-example
npm iNext, create a .env.local file by running the command below, and enter your public_token, and optionally project ID, secret, and Connected Apps client ID.
The Stytch public token should be stored in an environment variable named VITE_STYTCH_PUBLIC_TOKEN.
cp .env.template .env.localAfter completing all the set up steps above the application can be run with the command:
npm startThe application will be available at http://localhost:3000 using Vite's development server.
You'll be able to login with Email Magic Links and see your Stytch User object, Stytch Session, and see how logging out works.
To run the app with an API backend available at port 3001 for use with the Connected Apps CLI example, run the following command:
npm run serverThis example app showcases a small portion of what you can accomplish with Stytch. Here are a few ideas to explore:
- Add additional login methods like Passwords.
- Replace the prebuilt UI with your own using by using the SDK's headless methods.
- Add a Google OAuth button, or replace it with the high converting Google One Tap UI.
- Secure your app further by building MFA authentication using methods like Passkeys.
- Use Stytch Sessions to secure your backend.
Join the discussion, ask questions, and suggest new features in our Slack community!
Check out the Stytch Forum or email us at support@stytch.com.

