move to public repo
This commit is contained in:
29
client/src/context/ContextProvider.tsx
Normal file
29
client/src/context/ContextProvider.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { PropsWithChildren, useEffect, useState } from "react";
|
||||
import type { User } from "@types";
|
||||
|
||||
import { SocketContext, socket } from "./socket";
|
||||
import { SessionContext } from "./session";
|
||||
|
||||
import { fetchSession } from "../utils/auth";
|
||||
|
||||
const ContextProvider = (props: PropsWithChildren) => {
|
||||
const [user, setUser] = useState<User>({});
|
||||
|
||||
async function getSession() {
|
||||
const user = await fetchSession();
|
||||
if (user) {
|
||||
setUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getSession();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<SocketContext.Provider value={socket}>
|
||||
<SessionContext.Provider value={{ user, setUser }}>{props.children}</SessionContext.Provider>
|
||||
</SocketContext.Provider>
|
||||
);
|
||||
};
|
||||
export default ContextProvider;
|
||||
Reference in New Issue
Block a user