feat: add users question

This commit is contained in:
2026-08-20 18:48:22 +03:30
parent aba556618b
commit 96c74601c8
6 changed files with 365 additions and 11 deletions
+6 -8
View File
@@ -13,7 +13,6 @@ import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from "react";
import { APPRO_BASE_URL, MEDITATION_BASE_URL, PACKAGE_NAME } from "./config";
@@ -21,8 +20,10 @@ import {
ApiError,
apiFetch,
clearToken,
clearApproToken,
getToken,
setToken,
setApproToken,
toFormData,
} from "./api";
@@ -73,16 +74,12 @@ async function meditationLogin(approoToken: string): Promise<string> {
}
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [token, setTokenState] = useState<string | null>(null);
const [ready, setReady] = useState(false);
useEffect(() => {
setTokenState(getToken());
setReady(true);
}, []);
const [token, setTokenState] = useState<string | null>(() => getToken());
const [ready] = useState(true);
const login = useCallback(async (identifier: string, password: string) => {
const approoToken = await approAgencyLogin(identifier, password);
setApproToken(approoToken);
const medToken = await meditationLogin(approoToken);
setToken(medToken);
setTokenState(medToken);
@@ -90,6 +87,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const logout = useCallback(() => {
clearToken();
clearApproToken();
setTokenState(null);
}, []);