Server supabase structure
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import createClient from "@/actions/supa";
|
||||
|
||||
export async function getServerById(id: string) {
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error, data: server } = await supabase
|
||||
.from("servers")
|
||||
.select("id, name, created_at, owner, address, icon_url")
|
||||
.eq("id", id)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
if (!server) throw "Server is null";
|
||||
|
||||
return server;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { supabase } from "../../supa";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
|
||||
/**
|
||||
* GET /api/server/<id>
|
||||
*/
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
|
||||
const { data: profile } = await supabase
|
||||
.from("servers")
|
||||
.select("id, name, created_at, owner, address, icon_url")
|
||||
.eq("id", id)
|
||||
.maybeSingle();
|
||||
|
||||
if (!profile)
|
||||
return NextResponse.json(
|
||||
{ message: "not found" },
|
||||
{ status: StatusCodes.NOT_FOUND }
|
||||
);
|
||||
|
||||
return NextResponse.json({ message: "ok", ...profile });
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import App from "@/types/app";
|
||||
import ProfilePicture from "../ProfilePicture";
|
||||
import SettingsDialog from "../settings/SettingsDialog";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { getServerById } from "@/actions/get-server";
|
||||
|
||||
export default function SidebarServers({ app }: { app: App }) {
|
||||
const [newServer, setNewServer] = useState("");
|
||||
@@ -31,7 +32,7 @@ export default function SidebarServers({ app }: { app: App }) {
|
||||
const handleAddServer = async () => {
|
||||
if (!newServer || Object.hasOwn(app.servers, newServer)) return;
|
||||
try {
|
||||
const server = (await get(`/api/server/${newServer}`)).data as Server;
|
||||
const server = await getServerById(newServer);
|
||||
app.setServers((prev) => ({ ...prev, [server.id]: server }));
|
||||
Cookies.set("servers", Object.keys(app.servers).join(","));
|
||||
setNewServer("");
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Channel, Server } from "@/types/types";
|
||||
import Cookies from "js-cookie";
|
||||
import { toast } from "sonner";
|
||||
import { getProfileById } from "@/actions/get-profile";
|
||||
import { getServerById } from "@/actions/get-server";
|
||||
|
||||
export default function useApp(): App {
|
||||
const node = useRef<WebSocket | null>(null);
|
||||
@@ -30,11 +31,9 @@ export default function useApp(): App {
|
||||
.split(",")
|
||||
.map((x) => x.trim())
|
||||
.filter((id) => id)
|
||||
.map((id) => get(`/api/server/${id}`))
|
||||
.map((id) => getServerById(id))
|
||||
)
|
||||
.then((o) =>
|
||||
setServers(Object.fromEntries(o.map((i) => [i.data.id, i.data])))
|
||||
)
|
||||
.then((o) => setServers(Object.fromEntries(o.map((i) => [i.id, i]))))
|
||||
.catch(toast.error);
|
||||
}, []);
|
||||
|
||||
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
import { Message, Server } from "@/types/types";
|
||||
import axios from "axios";
|
||||
import { Dispatch, RefObject, SetStateAction } from "react";
|
||||
import { get } from "./request";
|
||||
import { toast } from "sonner";
|
||||
import { MessageStore } from "@/hooks/use-messages";
|
||||
import { IndicatorContext, ServerMessage } from "@/types/protocol";
|
||||
import { authRelay } from "@/actions/auth";
|
||||
import { getServerById } from "@/actions/get-server";
|
||||
|
||||
type AuthParams = {
|
||||
id: string;
|
||||
@@ -28,7 +27,7 @@ export default async function auth({
|
||||
|
||||
if (!id) return;
|
||||
|
||||
const ip = ((await get(`/api/server/${id}`)).data as any).address as string;
|
||||
const ip = (await getServerById(id)).address;
|
||||
|
||||
console.log("Authenticating with server at:", ip);
|
||||
const server_auth = await authRelay(id);
|
||||
|
||||
Reference in New Issue
Block a user