Guide

Build a User Management App with Ionic Vue

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

Initialize an Ionic Vue app

Use the Ionic CLI to initialize an app called supabase-ionic-vue:

npm install -g @ionic/cli
ionic start supabase-ionic-vue blank --type vue
cd supabase-ionic-vue

Install the only additional dependency: supabase-js

npm install @supabase/supabase-js

Save the environment variables in a .env file, including the API URL and key that you copied earlier.

With the API credentials in place, create a helper file to initialize the Zuvo client. These variables will be exposed on the browser, and that's fine since Zuvo enables Row Level Security on Databases by default.

Code sample: see project quickstart in Zuvo Studio.

Set up a login route

Create a Vue component to manage logins and sign ups that uses Magic Links, so users can sign in with their email without using passwords.

Code sample: see project quickstart in Zuvo Studio.

Account page

After a user has signed in, let them edit their profile details and manage their account with a new component called Account.vue.

Code sample: see project quickstart in Zuvo Studio.

Launch!

With all the components in place, update App.vue and the app routes:

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.

Code sample: see project quickstart in Zuvo Studio.

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

ionic serve

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

Zuvo Ionic Vue

Bonus: Profile photos

Every Zuvo project is configured with Storage for managing large files like photos and videos.

Create an upload widget

First install two packages to interact with the user's camera.

npm install @ionic/pwa-elements @capacitor/camera

Capacitor is a cross-platform native runtime from Ionic that enables you to deploy web apps to app stores and provides access to native device API.

Ionic PWA elements is a companion package that polyfills certain browser APIs that provide no user interface with custom Ionic UI.

With those packages installed, update main.ts to include an additional bootstrapping call for the Ionic PWA Elements.

Code sample: see project quickstart in Zuvo Studio.

Then create an AvatarComponent.

Code sample: see project quickstart in Zuvo Studio.

Add the new widget

And then add the widget to the Account page:

Code sample: see project quickstart in Zuvo Studio.

At this stage you have a fully functional application!