Capacitor - Drop Capacitor into any existing web project, framework or library. Convert an existing React, Svelte, Vue (or your preferred Web Framework) project to native mobile. - https://capacitorjs.com/
Ionic Framework - An open source mobile toolkit for building high quality, cross-platform native and web app experiences. Move faster with a single code base, running everywhere with JavaScript and the Web. - https://ionicframework.com/
Supabase - Supabase is an open source Firebase alternative. Start your project with a Postgres Database, Authentication, instant APIs, Realtime subscriptions and Storage. - https://supabase.com/
This is a series of videos walking you through how to get started with building a mobile application with Nuxt 3 and Ionic Capacitor. In this video, we add Supabase Account Creation and Authentication to the project and deploy it to a mobile device
Get Project Keys and Database URL, you will need them in the nuxt project configuration
SUPABASE_URL, SUPABASE_ANON_KEY
Setup And Configure Nuxt 3 Project
Install Supabase Javascript Client
npminstall@supabase/supabase-js
Set environment variables, since nuxt 3 has dotEnv built we can set the values in my configuration and read them in from a .env file to be used in the nuxt 3 configuration
Create Plugin and Composable For Managing Supabase Client
Create Supabase Client in Project, we will treat this as a plugin so it can run at startup. We will use the provide functionality to make the supabase client available to a composable that can be accessed anywhere in the app
// plugins/sb-client.tsexportdefaultdefineNuxtPlugin((nuxtApp)=>{constconfig=useRuntimeConfig();constsupabase=createClient(config.public.SUPABASE_URL,config.public.SUPABASE_ANON_KEY);// allow us to inject, see composables// nuxtApp.vueApp.provide('supabase', supabase);nuxtApp.provide('supabase',supabase);});
The composable
// composables/useSupabase.tsimporttype{SupabaseClient}from"@supabase/supabase-js";exportconstuseSupabase=():SupabaseClient=>{constapp=useNuxtApp();constsupabase=app.$supabase;if (!app.$supabase){console.log('supabase',supabase);thrownewError("Supabase Not Initialized Properly");}returnsupabaseasSupabaseClient;};
// use composableconstsupabase=useSupabase();// make api callconst{user,session,error}=awaitsupabase.auth.signIn({email:'example@email.com',password:'example-password',})
// use composableconstsupabase=useSupabase();// make api callconst{user,session,error}=awaitsupabase.auth.signUp({email:'example@email.com',password:'example-password',})
You can see in the middleware section below how we can access the state information. Pages can specify what middleware to run before rendering. We need the protected pages to check for a user, using the middleware, before rendering. The middleware will direct the user to the login page of there is no supabase user available