summaryrefslogtreecommitdiff
path: root/src/lib/contexts
diff options
context:
space:
mode:
authorl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-03-17 14:06:58 +0200
committerl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-03-17 14:06:58 +0200
commit646c1168349643eb01db53b5e06bf986a16b86d7 (patch)
tree1a47fed631b06179383ed75d1bacc3c6b785a974 /src/lib/contexts
parent9edce4dfa5f7c4efecd0f39fb4fd4a4c9863fe6e (diff)
simple registration prototype
Diffstat (limited to 'src/lib/contexts')
-rw-r--r--src/lib/contexts/Auth.context.tsx27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/lib/contexts/Auth.context.tsx b/src/lib/contexts/Auth.context.tsx
index ff2d369..d93ca92 100644
--- a/src/lib/contexts/Auth.context.tsx
+++ b/src/lib/contexts/Auth.context.tsx
@@ -1,36 +1,33 @@
'use client';
-
-import React, { createContext, use } from 'react';
-
+import React, { createContext, use, useState, useContext } from 'react';
type User = {
- id: string;
- avatar?: string;
- // Чёто там ещё
+ id: number;
+ username: string;
};
-interface AuthContext {
+interface AuthContextType {
user: User | null;
+ setUser: (user: User | null) => void;
}
const AuthContext = createContext<AuthContext | null>(null);
export const AuthContextProvider = ({ children }: React.PropsWithChildren) => {
- // TODO: подключить бэк
- const user = null;
+ const [user, setUser] = useState<User | null>(null);
+
return (
- <AuthContext.Provider value={{ user }}>{children}</AuthContext.Provider>
+ <AuthContext.Provider value={{ user, setUser }}>
+ {children}
+ </AuthContext.Provider>
);
};
export const useAuthContext = () => {
- const context = use(AuthContext);
-
- if (!context) {
+ const context = useContext(AuthContext);
+ if (!context)
throw new Error(
'useAuthContext must be used within AuthContextProvider',
);
- }
-
return context;
};