diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-ionic-angular.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-ionic-angular.mdx index e045805ec0f..582984e16fc 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-ionic-angular.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-ionic-angular.mdx @@ -38,7 +38,7 @@ Then let's install the only additional dependency: [supabase-js](https://github. npm install @supabase/supabase-js ``` -And finally we want to save the environment variables in the `environment.ts` file. +And finally, we want to save the environment variables in the `src/environments/environment.ts` file. All we need are the API URL and the `anon` key that you copied [earlier](#get-the-api-keys). These variables will be exposed on the browser, and that's completely fine since we have [Row Level Security](/docs/guides/auth#row-level-security) enabled on our Database. @@ -75,19 +75,19 @@ export class SupabaseService { } get user() { - return this.supabase.auth.user() + return this.supabase.auth.getUser().then(({ data }) => data?.user) } get session() { - return this.supabase.auth.session() + return this.supabase.auth.getSession().then(({ data }) => data?.session) } get profile() { - return this.supabase - .from('profiles') - .select(`username, website, avatar_url`) - .eq('id', this.user?.id) - .single() + return this.user + .then((user) => user?.id) + .then((id) => + this.supabase.from('profiles').select(`username, website, avatar_url`).eq('id', id).single() + ) } authChanges(callback: (event: AuthChangeEvent, session: Session | null) => void) { @@ -95,23 +95,22 @@ export class SupabaseService { } signIn(email: string) { - return this.supabase.auth.signIn({ email }) + return this.supabase.auth.signInWithOtp({ email }) } signOut() { return this.supabase.auth.signOut() } - updateProfile(profile: Profile) { + async updateProfile(profile: Profile) { + const user = await this.user const update = { ...profile, - id: this.user?.id, + id: user?.id, updated_at: new Date(), } - return this.supabase.from('profiles').upsert(update, { - returning: 'minimal', // Don't return the value after inserting - }) + return this.supabase.from('profiles').upsert(update) } downLoadImage(path: string) { @@ -135,8 +134,8 @@ export class SupabaseService { ### Set up a Login route -Let's set up an route to manage logins and sign ups. We'll use Magic Links, so users can sign in with their email without using passwords. -Create an **LoginPage** with `ionic g page login` Ionic CLI command. +Let's set up a route to manage logins and signups. We'll use Magic Links so users can sign in with their email without using passwords. +Create a **LoginPage** with the `ionic g page login` Ionic CLI command. > This guide will show the template inline, but the example app will have templateUrls @@ -173,20 +172,23 @@ import { SupabaseService } from '../supabase.service' `, styleUrls: ['./login.page.scss'], }) -export class LoginPage implements OnInit { +export class LoginPage { email = '' + constructor(private readonly supabase: SupabaseService) {} - ngOnInit() {} async handleLogin(event: any) { event.preventDefault() const loader = await this.supabase.createLoader() await loader.present() try { - await this.supabase.signIn(this.email) + const { error } = await this.supabase.signIn(this.email) + if (error) { + throw error + } await loader.dismiss() await this.supabase.createNotice('Check your email for the login link!') - } catch (error) { + } catch (error: any) { await loader.dismiss() await this.supabase.createNotice(error.error_description || error.message) } @@ -196,10 +198,10 @@ export class LoginPage implements OnInit { ### Account page -After a user is signed in we can allow them to edit their profile details and manage their account. +After a user is signed in, we can allow them to edit their profile details and manage their account. Create an **AccountComponent** with `ionic g page account` Ionic CLI command. -```ts src/app/account.component.ts +```ts src/app/account.page.ts import { Component, OnInit } from '@angular/core' import { Router } from '@angular/router' import { Profile, SupabaseService } from '../supabase.service' @@ -217,7 +219,7 @@ import { Profile, SupabaseService } from '../supabase.service'