Initial Commit

This commit is contained in:
Stavros
2025-01-19 13:40:06 +02:00
commit c0e085ea10
34 changed files with 3195 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { useQuery } from "@tanstack/react-query";
import React, { createContext, useContext } from "react";
import { UserContextSchemaType } from "../schemas/user-context-schema";
import axios from "axios";
const UserContext = createContext<UserContextSchemaType | null>(null);
export const UserContextProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const {
data: userContext,
isLoading,
error,
} = useQuery({
queryKey: ["isLoggedIn"],
queryFn: async () => {
const res = await axios.get("/api/status");
return res.data;
},
});
if (error && !isLoading) {
throw error;
}
return (
<UserContext.Provider value={userContext}>{children}</UserContext.Provider>
);
};
export const useUserContext = () => {
const context = useContext(UserContext);
if (context === null) {
throw new Error("useUserContext must be used within a UserContextProvider");
}
return context;
};