我的完整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);
}我知道这个错误:
属性'data‘在类型'{ user: User;会话: Session;error: ApiError;}上不存在
有人能帮忙吗?
发布于 2022-09-14 07:00:01
您需要将您的signUp()函数更改为:
async signUp(credentials: {email,password}){
const {error, user, session} = await this.supabase.auth.signUp(credentials);
}这样,您就有了一个user和session变量,如果您想要使用它,就可以使用它!通过查看代码,看起来您没有使用它们,所以您也可以这样省略它们。
async signUp(credentials: {email,password}){
await this.supabase.auth.signUp(credentials);
}https://stackoverflow.com/questions/73676026
复制相似问题