Ray
Ray

Reputation: 1

Property 'data' does not exist on type '{ user: User; session: Session; error: ApiError; }' in angular

My full supabase.service.ts code:

import { Injectable } from "@angular/core";
import { createClient, SupabaseClient, User } from "@supabase/supabase-js";
import { BehaviorSubject } from "rxjs";
import { environment } from "src/environments/environment";


@Injectable({
    providedIn: 'root'
}) 

export class SupabaseService {
    supabase: SupabaseClient;
    private _currentUser: BehaviorSubject<any> = new BehaviorSubject(null);

    constructor(){
        this.supabase = createClient(environment.supabaseUrl, environment.supabaseKey, {
            autoRefreshToken : true,
            persistSession: true
        });

        this.supabase.auth.onAuthStateChange(
            (event,session) => {
                console.log('event:', event);
                if(event == 'SIGNED_IN'){
                    this._currentUser.next(session.user);
                } else {
                    this._currentUser.next(false);
                }
            }
        );
    }


async signUp(credentials: {email,password}){
    const {error, data} = await this.supabase.auth.signUp(credentials);
}

}

On this part:

async signUp(credentials: {email,password}){
    const {error, data} = await this.supabase.auth.signUp(credentials);
}

I get this error:

Property 'data' does not exist on type '{ user: User; session: Session; error: ApiError; }

Could anybody help?

Upvotes: 0

Views: 1907

Answers (1)

dshukertjr
dshukertjr

Reputation: 18612

You need to change your signUp() function to the following:

async signUp(credentials: {email,password}){
    const {error, user, session} = await this.supabase.auth.signUp(credentials);
}

With this, you have a user and session variable that you can use if you want to do something with it! By taking a look at the code, it looks like you aren't using them, so you can omit them like this as well.

async signUp(credentials: {email,password}){
    await this.supabase.auth.signUp(credentials);
}

Upvotes: 1

Related Questions