我的完整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错误; }
有人能帮忙吗?
1条答案
按热度按时间62lalag41#
您需要将
signUp()
函数更改为以下内容:这样,您就有了一个
user
和session
变量,如果您想使用它们做一些事情,您可以使用它们!通过查看代码,您似乎没有使用它们,因此您也可以像这样省略它们。