Update artifacts/fb-publisher/src/App.tsx
Browse files- artifacts/fb-publisher/src/App.tsx +48 -108
artifacts/fb-publisher/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { useEffect, useRef, useState } from "react";
|
| 2 |
-
import {
|
| 3 |
import { setAuthTokenGetter } from "@workspace/api-client-react";
|
| 4 |
import {
|
| 5 |
Switch,
|
|
@@ -21,92 +21,37 @@ import Admin from "@/pages/Admin";
|
|
| 21 |
import NotFound from "@/pages/not-found";
|
| 22 |
import UpdateBanner from "@/components/UpdateBanner";
|
| 23 |
|
| 24 |
-
const
|
| 25 |
-
const
|
| 26 |
const basePath = import.meta.env.BASE_URL.replace(/\/$/, "");
|
| 27 |
|
| 28 |
-
function stripBase(path: string): string {
|
| 29 |
-
return basePath && path.startsWith(basePath)
|
| 30 |
-
? path.slice(basePath.length) || "/"
|
| 31 |
-
: path;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
if (!stackProjectId) {
|
| 35 |
-
throw new Error("Missing VITE_STACK_PROJECT_ID");
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
function SignInPage() {
|
| 39 |
-
return (
|
| 40 |
-
<div className="flex min-h-[100dvh] items-center justify-center px-4">
|
| 41 |
-
<SignIn
|
| 42 |
-
firstTab="password"
|
| 43 |
-
automaticRedirect={true}
|
| 44 |
-
redirectUrl={`${basePath}/app`}
|
| 45 |
-
/>
|
| 46 |
-
</div>
|
| 47 |
-
);
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
function SignUpPage() {
|
| 51 |
-
return (
|
| 52 |
-
<div className="flex min-h-[100dvh] items-center justify-center px-4">
|
| 53 |
-
<div className="w-full max-w-md space-y-4">
|
| 54 |
-
<SignUp
|
| 55 |
-
automaticRedirect={true}
|
| 56 |
-
redirectUrl={`${basePath}/app`}
|
| 57 |
-
/>
|
| 58 |
-
<div className="rounded-lg border border-red-500/30 bg-red-950/20 p-3 text-center text-sm text-red-300 backdrop-blur-sm">
|
| 59 |
-
⚠️ <strong>تنبيه هام لمكافحة السبام والرسائل المزعجة (Spam):</strong>{" "}
|
| 60 |
-
التسجيل باستخدام البريد الإلكتروني المؤقت (مثل{" "}
|
| 61 |
-
<code className="rounded bg-red-950/40 px-1">tempumail.art</code>)
|
| 62 |
-
ممنوع تمامًا وسيؤدي إلى <strong>حظر الحساب فور اكتشافه</strong>. يُرجى
|
| 63 |
-
استخدام بريد إلكتروني حقيقي ودائم.
|
| 64 |
-
</div>
|
| 65 |
-
</div>
|
| 66 |
-
</div>
|
| 67 |
-
);
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
function HomePage() {
|
| 71 |
-
const user = useUser();
|
| 72 |
-
|
| 73 |
-
if (user) {
|
| 74 |
-
return <Redirect to="/app" />;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
return <Landing />;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
function ProtectedPublisher() {
|
| 81 |
-
const
|
| 82 |
|
| 83 |
-
if (
|
| 84 |
-
|
| 85 |
-
}
|
| 86 |
|
| 87 |
return <Publisher />;
|
| 88 |
}
|
| 89 |
|
| 90 |
function ProtectedSubscription() {
|
| 91 |
-
const
|
| 92 |
-
|
| 93 |
-
if (!user) {
|
| 94 |
-
return <Redirect to="/sign-in" />;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
return <Subscription />;
|
| 98 |
}
|
| 99 |
|
| 100 |
function ProtectedExtension() {
|
| 101 |
-
const
|
| 102 |
-
|
| 103 |
-
if (!user) {
|
| 104 |
-
return <Redirect to="/sign-in" />;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
return <InstallExtension />;
|
| 108 |
}
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
function ServerKeepAlive() {
|
| 111 |
const [waking, setWaking] = useState(false);
|
| 112 |
|
|
@@ -141,22 +86,21 @@ function ServerKeepAlive() {
|
|
| 141 |
);
|
| 142 |
}
|
| 143 |
|
| 144 |
-
function
|
| 145 |
-
const
|
| 146 |
|
| 147 |
useEffect(() => {
|
| 148 |
setAuthTokenGetter(async () => {
|
| 149 |
-
|
| 150 |
-
return token ?? null;
|
| 151 |
});
|
| 152 |
return () => setAuthTokenGetter(null);
|
| 153 |
-
}, [
|
| 154 |
|
| 155 |
return null;
|
| 156 |
}
|
| 157 |
|
| 158 |
-
function
|
| 159 |
-
const user =
|
| 160 |
const qc = useQueryClient();
|
| 161 |
const prevUserIdRef = useRef<string | null | undefined>(undefined);
|
| 162 |
|
|
@@ -171,44 +115,40 @@ function StackQueryClientCacheInvalidator() {
|
|
| 171 |
return null;
|
| 172 |
}
|
| 173 |
|
| 174 |
-
function
|
| 175 |
-
const [, setLocation] = useLocation();
|
| 176 |
-
|
| 177 |
return (
|
| 178 |
-
<
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
| 181 |
>
|
| 182 |
-
<
|
| 183 |
-
<
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
<
|
| 188 |
-
<
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
</TooltipProvider>
|
| 202 |
-
</QueryClientProvider>
|
| 203 |
-
</StackTheme>
|
| 204 |
-
</StackProvider>
|
| 205 |
);
|
| 206 |
}
|
| 207 |
|
| 208 |
export default function App() {
|
| 209 |
return (
|
| 210 |
<WouterRouter base={basePath}>
|
| 211 |
-
<
|
| 212 |
</WouterRouter>
|
| 213 |
);
|
| 214 |
}
|
|
|
|
| 1 |
import { useEffect, useRef, useState } from "react";
|
| 2 |
+
import { KindeProvider, useKindeAuth } from "@kinde-oss/kinde-auth-react";
|
| 3 |
import { setAuthTokenGetter } from "@workspace/api-client-react";
|
| 4 |
import {
|
| 5 |
Switch,
|
|
|
|
| 21 |
import NotFound from "@/pages/not-found";
|
| 22 |
import UpdateBanner from "@/components/UpdateBanner";
|
| 23 |
|
| 24 |
+
const kindeDomain = import.meta.env.VITE_KINDE_DOMAIN as string;
|
| 25 |
+
const kindeClientId = import.meta.env.VITE_KINDE_CLIENT_ID as string;
|
| 26 |
const basePath = import.meta.env.BASE_URL.replace(/\/$/, "");
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
function ProtectedPublisher() {
|
| 29 |
+
const { isAuthenticated, isLoading } = useKindeAuth();
|
| 30 |
|
| 31 |
+
if (isLoading) return <div className="min-h-screen flex items-center justify-center"><div className="text-gray-300">جاري التحميل...</div></div>;
|
| 32 |
+
if (!isAuthenticated) return <Redirect to="/sign-in" />;
|
|
|
|
| 33 |
|
| 34 |
return <Publisher />;
|
| 35 |
}
|
| 36 |
|
| 37 |
function ProtectedSubscription() {
|
| 38 |
+
const { isAuthenticated } = useKindeAuth();
|
| 39 |
+
if (!isAuthenticated) return <Redirect to="/sign-in" />;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
return <Subscription />;
|
| 41 |
}
|
| 42 |
|
| 43 |
function ProtectedExtension() {
|
| 44 |
+
const { isAuthenticated } = useKindeAuth();
|
| 45 |
+
if (!isAuthenticated) return <Redirect to="/sign-in" />;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return <InstallExtension />;
|
| 47 |
}
|
| 48 |
|
| 49 |
+
function HomePage() {
|
| 50 |
+
const { isAuthenticated } = useKindeAuth();
|
| 51 |
+
if (isAuthenticated) return <Redirect to="/app" />;
|
| 52 |
+
return <Landing />;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
function ServerKeepAlive() {
|
| 56 |
const [waking, setWaking] = useState(false);
|
| 57 |
|
|
|
|
| 86 |
);
|
| 87 |
}
|
| 88 |
|
| 89 |
+
function KindeAuthTokenSetter() {
|
| 90 |
+
const { getToken } = useKindeAuth();
|
| 91 |
|
| 92 |
useEffect(() => {
|
| 93 |
setAuthTokenGetter(async () => {
|
| 94 |
+
return await getToken() ?? null;
|
|
|
|
| 95 |
});
|
| 96 |
return () => setAuthTokenGetter(null);
|
| 97 |
+
}, [getToken]);
|
| 98 |
|
| 99 |
return null;
|
| 100 |
}
|
| 101 |
|
| 102 |
+
function KindeQueryClientCacheInvalidator() {
|
| 103 |
+
const { user, isAuthenticated } = useKindeAuth();
|
| 104 |
const qc = useQueryClient();
|
| 105 |
const prevUserIdRef = useRef<string | null | undefined>(undefined);
|
| 106 |
|
|
|
|
| 115 |
return null;
|
| 116 |
}
|
| 117 |
|
| 118 |
+
function KindeProviderWithRoutes() {
|
|
|
|
|
|
|
| 119 |
return (
|
| 120 |
+
<KindeProvider
|
| 121 |
+
domain={kindeDomain}
|
| 122 |
+
clientId={kindeClientId}
|
| 123 |
+
redirectUri={`${window.location.origin}/api/kinde/callback`}
|
| 124 |
+
logoutUri={`${window.location.origin}`}
|
| 125 |
>
|
| 126 |
+
<QueryClientProvider client={queryClient}>
|
| 127 |
+
<ServerKeepAlive />
|
| 128 |
+
<KindeAuthTokenSetter />
|
| 129 |
+
<KindeQueryClientCacheInvalidator />
|
| 130 |
+
<TooltipProvider>
|
| 131 |
+
<Switch>
|
| 132 |
+
<Route path="/" component={HomePage} />
|
| 133 |
+
<Route path="/app" component={ProtectedPublisher} />
|
| 134 |
+
<Route path="/subscription" component={ProtectedSubscription} />
|
| 135 |
+
<Route path="/subscription/return" component={SubscriptionReturn} />
|
| 136 |
+
<Route path="/extension" component={ProtectedExtension} />
|
| 137 |
+
<Route path="/admin" component={Admin} />
|
| 138 |
+
<Route component={NotFound} />
|
| 139 |
+
</Switch>
|
| 140 |
+
<UpdateBanner />
|
| 141 |
+
<Toaster />
|
| 142 |
+
</TooltipProvider>
|
| 143 |
+
</QueryClientProvider>
|
| 144 |
+
</KindeProvider>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
);
|
| 146 |
}
|
| 147 |
|
| 148 |
export default function App() {
|
| 149 |
return (
|
| 150 |
<WouterRouter base={basePath}>
|
| 151 |
+
<KindeProviderWithRoutes />
|
| 152 |
</WouterRouter>
|
| 153 |
);
|
| 154 |
}
|