Tiny auth error tweaks, also ! on greet
This commit is contained in:
@@ -40,7 +40,7 @@ export default function ChatHub() {
|
|||||||
<div onClick={() => app.setSidebarOpen(true)}>
|
<div onClick={() => app.setSidebarOpen(true)}>
|
||||||
<h1 className="text-3xl font-bold flex cursor-pointer gap-2">
|
<h1 className="text-3xl font-bold flex cursor-pointer gap-2">
|
||||||
<ChevronLeft className="my-auto w-5 md:hidden" />
|
<ChevronLeft className="my-auto w-5 md:hidden" />
|
||||||
Hey {app.profile?.display_name || "there"}
|
Hey {app.profile?.display_name || "there"}!
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
Here's what's happening in your network today.
|
Here's what's happening in your network today.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Message, Server } from "@/types/types";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Dispatch, RefObject, SetStateAction } from "react";
|
import { Dispatch, RefObject, SetStateAction } from "react";
|
||||||
import { get } from "./request";
|
import { get } from "./request";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export default async function auth(
|
export default async function auth(
|
||||||
id: string,
|
id: string,
|
||||||
@@ -22,6 +23,8 @@ export default async function auth(
|
|||||||
(await axios.post("/api/auth", { server_id: id })).data as any
|
(await axios.post("/api/auth", { server_id: id })).data as any
|
||||||
).token;
|
).token;
|
||||||
|
|
||||||
|
var name = id;
|
||||||
|
|
||||||
// Open the WebSocket connection
|
// Open the WebSocket connection
|
||||||
const ws = new WebSocket(`wss://${ip}`);
|
const ws = new WebSocket(`wss://${ip}`);
|
||||||
wsRef.current = ws;
|
wsRef.current = ws;
|
||||||
@@ -34,6 +37,13 @@ export default async function auth(
|
|||||||
const data = JSON.parse(m.data);
|
const data = JSON.parse(m.data);
|
||||||
console.log("Message received:", data);
|
console.log("Message received:", data);
|
||||||
|
|
||||||
|
if (data.error) {
|
||||||
|
toast.error(`Error from ${name} (${data.error})`, {
|
||||||
|
description: data.message,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.version) {
|
if (data.version) {
|
||||||
setServer({ channels: [], ...data });
|
setServer({ channels: [], ...data });
|
||||||
ws.send(
|
ws.send(
|
||||||
@@ -43,6 +53,7 @@ export default async function auth(
|
|||||||
last_message: lastMessage || 0,
|
last_message: lastMessage || 0,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
name = data.name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +71,24 @@ export default async function auth(
|
|||||||
|
|
||||||
ws.onerror = (err) => {
|
ws.onerror = (err) => {
|
||||||
console.error("WebSocket error:", err);
|
console.error("WebSocket error:", err);
|
||||||
|
|
||||||
|
let description = "An unknown WebSocket error occurred.";
|
||||||
|
|
||||||
|
if (err instanceof ErrorEvent) {
|
||||||
|
// Browser WebSocket errors show up here
|
||||||
|
description =
|
||||||
|
err.message || err.error?.message || "WebSocket connection failed.";
|
||||||
|
} else if (err instanceof Event) {
|
||||||
|
// Generic Event (no info)
|
||||||
|
description = "WebSocket encountered a network issue.";
|
||||||
|
} else if (err && typeof err === "object") {
|
||||||
|
// Custom data if something special got passed
|
||||||
|
description = JSON.stringify(err, null, 2);
|
||||||
|
} else {
|
||||||
|
description = String(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.error(`WebSocket error (${name})`, { description });
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user