@mdguggenbichler/slugbase-core 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,19 +52,44 @@ function SharedRedirect() {
52
52
  return <Navigate to={to} replace />;
53
53
  }
54
54
 
55
+ /** Diagnostic: catches errors in login subtree and rethrows with a prefix so cloud boundary shows where the throw came from. */
56
+ class LoginRouteErrorBoundary extends Component<{ children: ReactNode }, { error: Error | null }> {
57
+ state = { error: null as Error | null };
58
+
59
+ static getDerivedStateFromError(raw: unknown): { error: Error } {
60
+ const msg = raw instanceof Error ? raw.message : String(raw);
61
+ return { error: new Error(`[LoginRoute] ${msg || '(no message)'}`) };
62
+ }
63
+
64
+ componentDidCatch(error: unknown, info: React.ErrorInfo) {
65
+ console.error('[Login route boundary]', error, info.componentStack);
66
+ }
67
+
68
+ render() {
69
+ if (this.state.error != null) throw this.state.error;
70
+ return this.props.children;
71
+ }
72
+ }
73
+
55
74
  function AppRoutes() {
56
75
  const { user, loading } = useAuth();
57
76
  const { t } = useTranslation();
58
- const { appRootPath } = useAppConfig();
59
- const [setupStatus, setSetupStatus] = React.useState<{ initialized: boolean } | null>(null);
60
- const [setupLoading, setSetupLoading] = React.useState(true);
77
+ const { appRootPath, skipSetupFlow } = useAppConfig();
78
+ const [setupStatus, setSetupStatus] = React.useState<{ initialized: boolean } | null>(() =>
79
+ skipSetupFlow ? { initialized: true } : null
80
+ );
81
+ const [setupLoading, setSetupLoading] = React.useState(() => !skipSetupFlow);
61
82
 
62
83
  React.useEffect(() => {
84
+ if (skipSetupFlow) {
85
+ setSetupLoading(false);
86
+ return;
87
+ }
63
88
  api.get('/auth/setup/status')
64
89
  .then((res) => res.data)
65
90
  .then((data) => { setSetupStatus(data); setSetupLoading(false); })
66
91
  .catch(() => { setSetupStatus({ initialized: true }); setSetupLoading(false); });
67
- }, []);
92
+ }, [skipSetupFlow]);
68
93
 
69
94
  if (setupLoading || (loading && setupStatus?.initialized)) {
70
95
  return <div className="min-h-screen flex items-center justify-center"><div className="text-lg">{t('common.loading')}</div></div>;
@@ -76,7 +101,7 @@ function AppRoutes() {
76
101
  return (
77
102
  <Suspense fallback={<div className="min-h-screen flex items-center justify-center"><div className="text-lg">{t('common.loading')}</div></div>}>
78
103
  <Routes>
79
- <Route path="/login" element={!user ? <Login /> : <Navigate to={appRootPath} replace />} />
104
+ <Route path="/login" element={!user ? <LoginRouteErrorBoundary><Login /></LoginRouteErrorBoundary> : <Navigate to={appRootPath} replace />} />
80
105
  <Route path="/signup" element={!user ? <Signup /> : <Navigate to={appRootPath} replace />} />
81
106
  <Route path="/reset-password" element={<PasswordReset />} />
82
107
  <Route path="/password-reset" element={<PasswordReset />} />
@@ -198,9 +223,11 @@ export interface AppProps {
198
223
  apiBaseUrl?: string;
199
224
  /** When set (e.g. "" or null), core does not render BrowserRouter; host (e.g. cloud) provides it. */
200
225
  routerBasename?: string | null;
226
+ /** When true, skip the first-time setup flow (e.g. in cloud; first user registers via Signup). */
227
+ skipSetupFlow?: boolean;
201
228
  }
202
229
 
203
- function App({ basePath, apiBaseUrl, routerBasename }: AppProps = {}) {
230
+ function App({ basePath, apiBaseUrl, routerBasename, skipSetupFlow }: AppProps = {}) {
204
231
  const appRootPath = basePath === '/' || !basePath ? '/' : basePath;
205
232
  const content = (
206
233
  <AuthProvider>
@@ -213,7 +240,7 @@ function App({ basePath, apiBaseUrl, routerBasename }: AppProps = {}) {
213
240
  );
214
241
  return (
215
242
  <AppErrorBoundary>
216
- <AppConfigProvider appBasePath={basePath} apiBaseUrl={apiBaseUrl} appRootPath={appRootPath}>
243
+ <AppConfigProvider appBasePath={basePath} apiBaseUrl={apiBaseUrl} appRootPath={appRootPath} skipSetupFlow={skipSetupFlow}>
217
244
  {routerBasename !== undefined ? (
218
245
  content
219
246
  ) : (
@@ -5,6 +5,8 @@ export interface AppConfig {
5
5
  appBasePath: string;
6
6
  apiBaseUrl: string;
7
7
  appRootPath: string;
8
+ /** When true, skip the first-time setup flow (e.g. in cloud; first user registers via Signup). */
9
+ skipSetupFlow?: boolean;
8
10
  }
9
11
 
10
12
  const defaultConfig: AppConfig = {
@@ -20,16 +22,19 @@ export function AppConfigProvider({
20
22
  appBasePath,
21
23
  apiBaseUrl,
22
24
  appRootPath,
25
+ skipSetupFlow,
23
26
  }: {
24
27
  children: React.ReactNode;
25
28
  appBasePath?: string;
26
29
  apiBaseUrl?: string;
27
30
  appRootPath?: string;
31
+ skipSetupFlow?: boolean;
28
32
  }) {
29
33
  const value: AppConfig = {
30
34
  appBasePath: appBasePath ?? defaultConfig.appBasePath,
31
35
  apiBaseUrl: apiBaseUrl ?? defaultConfig.apiBaseUrl,
32
36
  appRootPath: appRootPath ?? defaultConfig.appRootPath,
37
+ skipSetupFlow,
33
38
  };
34
39
  return <AppConfigContext.Provider value={value}>{children}</AppConfigContext.Provider>;
35
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdguggenbichler/slugbase-core",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "SlugBase core: backend and frontend entrypoints for self-hosted and cloud apps",
5
5
  "type": "module",
6
6
  "exports": {