async authenticateOwner(opts: Record<any, any>) {
const { ctx } = opts;
const jwt = this.getClientSupabaseJWT(ctx);
const userDetails = await this.authenticateUser(jwt);
const clientOrganizationId = this.getClientOrganizationId(ctx);
const { data, error } = await supabase
.from("users_secure_metadata")
.select("*")
.eq("user_id", userDetails.id)
.eq("organization_id", clientOrganizationId)
.single();
if (error || !data) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
if (data.organization_role !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const userWithMetadata: IUserWithMetadata = {
metadata: data,
user: userDetails,
};
return opts.next({
ctx: {
user: userWithMetadata,
},
});
}
async authenticateOwner(opts: Record<any, any>) {
const { ctx } = opts;
const jwt = this.getClientSupabaseJWT(ctx);
const userDetails = await this.authenticateUser(jwt);
const clientOrganizationId = this.getClientOrganizationId(ctx);
const { data, error } = await supabase
.from("users_secure_metadata")
.select("*")
.eq("user_id", userDetails.id)
.eq("organization_id", clientOrganizationId)
.single();
if (error || !data) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
if (data.organization_role !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const userWithMetadata: IUserWithMetadata = {
metadata: data,
user: userDetails,
};
return opts.next({
ctx: {
user: userWithMetadata,
},
});
}