Skip to content

Authenticate your ZITADEL users within your react applications

zitadel/zitadel-react

Repository files navigation

@zitadel/react Quickstart SPA

Zitadel Logo

Authenticate your ZITADEL users within your React applications.

Important

If you want to try out @zitadel/react, read the ZITADEL step-by-step guide for React. It shows how to get the authority and client_id from ZITADEL and how to wire everything up in React.

Project Structure

This project is a default React application created with Create React App that contains the ZITADEL React SDK to handle OIDC. The library is located in /lib folder and published as @zitadel/react.

NPM Version NPM License PRs Welcome

The following pages are added to the scaffolded example application:

  • src/components/Login.tsx: The login page shows a button if no user is authenticated and redirects the user to /callback if authenticated.
  • src/components/Callback.tsx: This page completes the auth flow and renders the retrieved information from the user info endpoint.

Available scripts

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Setup Instructions

  1. Log into the Zitadel Customer Portal
    Go to the Zitadel Customer Portal

  2. Create an Instance

    • Choose a region and create your new instance.
  3. Create a Project

    • Inside your instance, go to Projects -> Create New Project

App Screenshot

  1. Create an Application
    • New "User Agent"
    • Select "PKCE"
    • Enable "Development Mode"
    • Configure your Redirect URI and Post Logout URI (http://localhost:3000 for local testing)
    • Click "Continue" and "Create"
    • Copy the "Client ID"

App Screenshot

  1. Change your token type to JWT in your application settings

App Screenshot

  1. Configure ZitadelConfig
    Open src/App.tsx and replace the placeholder for authority and client_id values with your application info:
const config: ZitadelConfig = {
    authority: "https://CUSTOM_DOMAIN",
    client_id: "YOUR_CLIENT_ID",
    redirect_uri: "http://localhost:3000/callback",
    post_logout_redirect_uri: "http://localhost:3000",
    response_type: 'code',
    scope: 'openid profile email'
};
  1. Run the application

To run the example, navigate to the /lib folder and run yarn build.

cd ./lib
yarn install
yarn build

Then, navigate back and install the dependencies

cd ..
yarn install
yarn start

Your application will then run on http://localhost:3000

About

Authenticate your ZITADEL users within your react applications

Topics

Resources

Stars

Watchers

Forks

Contributors 12