Working supabase structure
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
"use server";
|
||||
|
||||
import createClient from "@/lib/supa";
|
||||
import createClient from "@/actions/supa";
|
||||
import { ProfileSettings } from "@/types/settings";
|
||||
import getSession from "./get-session";
|
||||
import { UserProfile } from "@/hooks/get-user";
|
||||
|
||||
export async function getProfileById(id: string) {
|
||||
export async function getProfileById(id: string): Promise<UserProfile | null> {
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error, data } = await supabase
|
||||
@@ -17,3 +20,39 @@ export async function getProfileById(id: string) {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getProfileByUsername(
|
||||
username: string
|
||||
): Promise<UserProfile | null> {
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error, data } = await supabase
|
||||
.from("profiles")
|
||||
.select("id, username, display_name, avatar_url, node_address")
|
||||
.eq("username", username)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function updateProfile(profile: ProfileSettings) {
|
||||
const supabase = await createClient();
|
||||
const user_id = await getSession();
|
||||
|
||||
if (!user_id) {
|
||||
throw new Error("User id invalid");
|
||||
}
|
||||
|
||||
const { error } = await supabase
|
||||
.from("profiles")
|
||||
.update(profile)
|
||||
.eq("id", user_id);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import createClient from "@/lib/supa";
|
||||
import createClient from "@/actions/supa";
|
||||
|
||||
export default async function getSession() {
|
||||
const supabase = await createClient();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import createClient from "@/lib/supa";
|
||||
import createClient from "@/actions/supa";
|
||||
|
||||
export default async function loginServer(email: string, password: string) {
|
||||
const supabase = await createClient();
|
||||
|
||||
Reference in New Issue
Block a user