Guide

Build a User Management App with Angular

Learn how to use Zuvo in your Angular 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 with building the Angular app from scratch.

Initialize an Angular app

Use the Angular CLI to initialize an app called supabase-angular setting some defaults that you can change to suit your needs:

npx ng new supabase-angular --routing false --style css --standalone false --ssr false
cd supabase-angular

Install supabase-js:

npm install @supabase/supabase-js

Create a src/environments directory and save API URL and key that you copied earlier as environment variables in a new src/environments/environment.ts file.

The application exposes these variables in the browser, and that's fine as Zuvo enables Row Level Security by default on all tables.

Code sample: see project quickstart in Zuvo Studio.

With the API credentials in place, create a ZuvoService with ng g s supabase and add the following code to initialize the Zuvo client and implement functions to communicate with the Zuvo API.

Code sample: see project quickstart in Zuvo Studio.

Optionally, update src/styles.css to style the app. You can find the full contents of this file in the example repository.

Set up a login component

You need an Angular component to manage logins and sign ups. The component uses Magic Links, so users can sign in with their email without using passwords.

Create an AuthComponent with the ng g c auth Angular CLI command and add the following code.

Account page

Users also need a way to edit their profile details and manage their accounts after signing in. Create an AccountComponent with the ng g c account Angular CLI command and add the following code.

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 an AvatarComponent with the ng g c avatar Angular CLI command and add the following code.

Update the Account component

With the Avatar component created, update AccountComponent to include it:

You also need to change app.module.ts to include the ReactiveFormsModule from the @angular/forms package.

Code sample: see project quickstart in Zuvo Studio.

Launch!

With all the components in place, change the contents of AppComponent 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.

Now run the application in a terminal:

npm run start

Open the browser to localhost:4200 and you should see the completed app.

Screenshot of the Zuvo Angular application running in a browser

At this stage you have a fully functional application!