Websocket and auth fixes

This commit is contained in:
2025-10-15 15:14:27 +02:00
parent 8b562a37b2
commit cf32a2b778
7 changed files with 54 additions and 41 deletions
+3 -1
View File
@@ -5,6 +5,7 @@ import Cookies from "js-cookie";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { get } from "@/lib/request";
import { toast } from "sonner";
export interface UserProfile extends ProfileSettings {
id: string;
@@ -24,8 +25,9 @@ export default function useUser() {
try {
setUser((await get("/api/profile")).data);
} catch {
} catch (e: any) {
router.push("/login");
toast.error(`Error: ${e}`);
}
}
+3 -5
View File
@@ -2,6 +2,7 @@
import { defaultSettings, getClientSettings } from "@/lib/clientSettings";
import { ProfileSettings, ClientSettings } from "@/types/settings";
import axios from "axios";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
export function useClientSettings(): [
@@ -31,11 +32,8 @@ export function useProfileSettings(): [
useEffect(() => {
async function fetchProfileSettings() {
try {
const res = await fetch("/api/profile");
if (res.ok) {
const data = (await res.json()) as ProfileSettings;
setSettings(data);
}
const res = await axios.get("/api/profile");
setSettings(res.data as ProfileSettings);
} catch (error) {
console.error("Failed to fetch profile settings:", error);
}