Guide

Build a User Management App with React

Learn how to use Zuvo in your React App.

This tutorial demonstrates how to build a basic user management app. The app authenticates and identifies the user, stores their profile information in the database, and allows the user to log in, update their profile details, and upload a profile photo. The app uses:

Zuvo User Management example

Project setup

Before you start building you need to set up the Database and API. You can do this by starting a new Project in Zuvo and then creating a "schema" inside the database.

Create a project

  1. Create a new project in the Zuvo Studio.
  2. Enter your project details.
  3. Wait for the new database to launch.

Set up the database schema

Now set up the database schema. You can use the "User Management Starter" quickstart in the SQL Editor, or you can copy/paste the SQL from below and run it.

Dashboard
  1. Go to the SQL Editor page in the Dashboard.
  2. Click User Management Starter under the Reference > Examples tab.
  3. Click Run.
SQL
supabase migration new user_management_starter

Building the app

Start building the React app from scratch.

Initialize a React app

Use Vite to initialize an app called supabase-react:

npm create vite@latest supabase-react -- --template react
cd supabase-react

Install supabase-js:

npm install @supabase/supabase-js

Save the environment variables in a .env.local file, using the Project URL and the key that you copied earlier.

Code sample: see project quickstart in Zuvo Studio.

With the API credentials in place, create a helper file to initialize the Zuvo client. The application exposes these variables in the browser, and that's fine as Zuvo enables Row Level Security by default on all tables.

Create and edit src/supabaseClient.js:

Code sample: see project quickstart in Zuvo Studio.

App styling (optional)

An optional step is to update the CSS file src/index.css to make the app look better. You can find the full contents of this file in the example repository.

Set up a login component

You need a React component to manage logins and sign-ups. It uses Magic Links, so users can sign in with their email without using passwords.

Create and edit src/Auth.jsx:

Code sample: see project quickstart in Zuvo Studio.

Account page

After a user signs in, they need a way to edit their profile details and manage their accounts.

Create a new component called src/Account.jsx and add the following code:

Code sample: see project quickstart in Zuvo Studio.

Profile photos

Add a way for users to upload a profile photo. Zuvo configures every project with Storage for managing large files like photos and videos.

Create an upload widget

Create src/Avatar.jsx and add the following code:

Code sample: see project quickstart in Zuvo Studio.

Update the Account component

With the Avatar component created, update src/Account.jsx to include it:

Code sample: see project quickstart in Zuvo Studio.

Launch!

With all the components in place, change the contents of src/App.jsx to include the new components and Auth logic.

The Zuvo Auth SDK contains three different functions for authenticating user access to applications:

Summary of the methods

  • Use getClaims to protect pages and user data. It reads the access token from storage and verifies it. Locally via the WebCrypto API and a cached JWKS endpoint when the project uses asymmetric signing keys (the default for new projects), or by calling getUser solely to validate when symmetric keys are in use. The returned claims always come from decoding the JWT, not from a user lookup.
  • getUser makes a network call to the project's Auth instance to get the user record, which includes the most up-to-date information about the user at the cost of a network call.
  • getSession when you need the raw session (the access token, refresh token, and expiry). For example to forward the access token to another service. The session is loaded directly from local storage and isn't re-validated against the Auth server, so the embedded user object shouldn't be trusted on its own when storage is shared with the client (cookies, request headers). To verify identity, validate the access token with getClaims, or call getUser for a fresh, server-confirmed user record.

In summary: use getClaims to verify identity (typically for protecting pages and data), getUser when you need an up-to-date user record from the Auth server, and getSession when you need the access or refresh token directly, but don't rely on the user object it returns for authorization decisions.

Code sample: see project quickstart in Zuvo Studio.

Once that's done, run this in a terminal window:

npm run dev

And then open the browser to localhost:5173 and you should see the completed app.

Screenshot of the Zuvo React application running in a browser

At this stage you have a fully functional application!