Working supabase structure

This commit is contained in:
2025-12-23 15:24:59 +01:00
parent b629b9a6e2
commit a39c4fa26d
10 changed files with 52 additions and 260 deletions
+41 -2
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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();