Ionic 类型“{ user:用户;会话:会话;错误:Angular 中出现ApiError; }'

xxe27gdn  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(95)

我的完整supabase.service.ts代码:

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);
}

}

在此零件上:

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

我得到这个错误:
类型“{ user:用户;会话:会话;错误:Api错误; }
有人能帮忙吗?

62lalag4

62lalag41#

您需要将signUp()函数更改为以下内容:

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

这样,您就有了一个usersession变量,如果您想使用它们做一些事情,您可以使用它们!通过查看代码,您似乎没有使用它们,因此您也可以像这样省略它们。

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

相关问题