Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants. Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
import { api, type MeResponse } from "@/lib/api";
|
|
import { getStoredToken } from "@/lib/auth";
|
|
|
|
/** بارگذاری وضعیت کاربر جاری (عضویتها و نیاز به onboarding) از `/api/v1/me`. */
|
|
export function useMe() {
|
|
const [me, setMe] = useState<MeResponse | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState("");
|
|
|
|
const load = useCallback(async () => {
|
|
if (!getStoredToken()) {
|
|
setMe(null);
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
setLoading(true);
|
|
setError("");
|
|
try {
|
|
const data = await api.me.get();
|
|
setMe(data);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : "خطا در دریافت اطلاعات کاربر");
|
|
setMe(null);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
load();
|
|
}, [load]);
|
|
|
|
return { me, loading, error, reload: load };
|
|
}
|