summaryrefslogtreecommitdiff
path: root/src/lib/contexts
diff options
context:
space:
mode:
authorl3wdfut4pwr <l3wdfut4pwr@gmail.com>2025-12-30 13:46:39 +0200
committerl3wdfut4pwr <l3wdfut4pwr@gmail.com>2025-12-30 13:46:39 +0200
commitc3dcb9c827df6d80ad1b0b1a7c6155561527b39d (patch)
tree76d8b9e706f9e8fcf7acc157a633905ff16c6b74 /src/lib/contexts
init
Diffstat (limited to 'src/lib/contexts')
-rw-r--r--src/lib/contexts/Auth.context.tsx37
-rw-r--r--src/lib/contexts/Global.context.tsx8
-rw-r--r--src/lib/contexts/index.ts2
3 files changed, 47 insertions, 0 deletions
diff --git a/src/lib/contexts/Auth.context.tsx b/src/lib/contexts/Auth.context.tsx
new file mode 100644
index 0000000..ff2d369
--- /dev/null
+++ b/src/lib/contexts/Auth.context.tsx
@@ -0,0 +1,37 @@
+'use client';
+
+import React, { createContext, use } from 'react';
+
+type User = {
+ id: string;
+ avatar?: string;
+ // Чёто там ещё
+};
+
+interface AuthContext {
+ user: User | null;
+}
+
+const AuthContext = createContext<AuthContext | null>(null);
+
+export const AuthContextProvider = ({ children }: React.PropsWithChildren) => {
+ // TODO: подключить бэк
+ const user = null;
+ return (
+ <AuthContext.Provider value={{ user }}>{children}</AuthContext.Provider>
+ );
+};
+
+export const useAuthContext = () => {
+ const context = use(AuthContext);
+
+ if (!context) {
+ throw new Error(
+ 'useAuthContext must be used within AuthContextProvider',
+ );
+ }
+
+ return context;
+};
+
+export const useUser = () => useAuthContext().user;
diff --git a/src/lib/contexts/Global.context.tsx b/src/lib/contexts/Global.context.tsx
new file mode 100644
index 0000000..3f8b61b
--- /dev/null
+++ b/src/lib/contexts/Global.context.tsx
@@ -0,0 +1,8 @@
+import React from 'react';
+import { AuthContextProvider } from './Auth.context';
+
+export const GlobalContextProvider = ({
+ children,
+}: React.PropsWithChildren) => {
+ return <AuthContextProvider>{children}</AuthContextProvider>;
+};
diff --git a/src/lib/contexts/index.ts b/src/lib/contexts/index.ts
new file mode 100644
index 0000000..61ebbe8
--- /dev/null
+++ b/src/lib/contexts/index.ts
@@ -0,0 +1,2 @@
+export * from './Auth.context';
+export * from './Global.context';