@lowdefy/server-dev 0.0.0-experimental-20260814133003 → 0.0.0-experimental-20260821084134

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.
Files changed (82) hide show
  1. package/client/Page.jsx +13 -4
  2. package/client/Reload.jsx +8 -0
  3. package/client/Routing.jsx +31 -23
  4. package/lib/client/RedirectingPage.jsx +56 -0
  5. package/lib/client/auth/Auth.jsx +3 -5
  6. package/lib/client/auth/AuthConfigured.jsx +184 -37
  7. package/lib/client/auth/AuthNotConfigured.js +23 -2
  8. package/lib/client/auth/authTemplateSync.test.mjs +40 -0
  9. package/lib/client/auth/betterAuthSessionContract.test.mjs +181 -0
  10. package/lib/client/utils/usePageConfig.js +36 -32
  11. package/lib/client/utils/usePageConfig.test.mjs +62 -0
  12. package/lib/docs/checkpointStore.js +8 -2
  13. package/lib/docs/createDocsMcpServer.js +34 -9
  14. package/lib/docs/createDocsMcpServer.test.mjs +18 -0
  15. package/lib/docs/evalOperator.js +18 -10
  16. package/lib/docs/evalOperator.test.mjs +47 -2
  17. package/lib/docs/evalOperatorHeadless.js +2 -2
  18. package/lib/docs/getBrowser.js +15 -3
  19. package/lib/docs/getBrowser.test.mjs +120 -0
  20. package/lib/docs/inspectState.js +15 -9
  21. package/lib/docs/inspectState.test.mjs +53 -4
  22. package/lib/docs/inspectStateHeadless.js +2 -2
  23. package/lib/docs/loadState.js +15 -2
  24. package/lib/docs/resolveSource.js +48 -0
  25. package/lib/docs/resolveSource.test.mjs +100 -0
  26. package/lib/docs/screenshotPage.js +2 -1
  27. package/lib/docs/stateCheckpoints.test.mjs +18 -0
  28. package/lib/server/auth/createSystemContext.js +70 -0
  29. package/lib/server/auth/getAuth.js +46 -0
  30. package/lib/server/auth/getHeadlessUser.js +7 -8
  31. package/lib/server/auth/getMockUser.js +11 -7
  32. package/lib/server/auth/{getAuthConfig.js → getStrategies.js} +12 -10
  33. package/lib/server/auth/headlessUser.js +3 -2
  34. package/lib/server/auth/resolveHeadlessUser.js +38 -0
  35. package/lib/server/auth/resolveHeadlessUser.test.mjs +74 -0
  36. package/lib/server/auth/strategies.js +47 -0
  37. package/lib/server/createLowdefyContext.js +93 -38
  38. package/lib/server/getPageJitEnrichment.test.mjs +105 -0
  39. package/lib/server/jitPageBuilder.js +90 -2
  40. package/lib/server/loadDynamicJsMap.js +47 -0
  41. package/lib/server/log/createHandleError.js +9 -0
  42. package/lib/server/log/createHandleError.test.mjs +126 -0
  43. package/lib/server/log/logRequest.js +1 -3
  44. package/manager/processes/startServer.mjs +0 -2
  45. package/manager/utils/createCustomPluginTypesMap.mjs +2 -2
  46. package/manager/watchers/serverArtifactWatcher.mjs +0 -2
  47. package/package.json +37 -34
  48. package/package.original.json +37 -34
  49. package/src/app.js +38 -19
  50. package/src/html/renderDevPage.js +1 -1
  51. package/src/middleware/errorHandler.js +26 -9
  52. package/src/middleware/errorHandler.test.mjs +287 -0
  53. package/src/{lib/serveBuildJs.js → middleware/mcpOrgGuard.js} +9 -10
  54. package/src/middleware/mcpOrgGuard.test.mjs +44 -0
  55. package/src/routes/auth.js +15 -21
  56. package/src/routes/detached.js +10 -6
  57. package/src/routes/docs/evalOperator.js +12 -2
  58. package/src/routes/docs/inspectState.js +12 -2
  59. package/src/routes/docs/loadState.js +14 -3
  60. package/src/routes/docs/parseUserParam.js +52 -0
  61. package/src/routes/docs/parseUserParam.test.mjs +45 -0
  62. package/src/routes/docs/runRequest.js +2 -4
  63. package/src/routes/docs/screenshot.js +7 -1
  64. package/src/routes/endpoints.js +14 -9
  65. package/src/routes/jitPage.js +50 -4
  66. package/src/routes/jitPage.test.mjs +107 -0
  67. package/src/routes/mcp.js +94 -0
  68. package/src/routes/mcp.test.mjs +184 -0
  69. package/src/routes/mcpProtectedResourceMetadata.js +39 -0
  70. package/src/routes/mcpProtectedResourceMetadata.test.mjs +79 -0
  71. package/src/routes/mountOauthDiscovery.js +47 -0
  72. package/src/routes/mountOauthDiscovery.test.mjs +79 -0
  73. package/src/routes/request.js +2 -8
  74. package/src/routes/{iconsDynamic.js → user.js} +9 -7
  75. package/lib/server/auth/getDevSession.js +0 -70
  76. package/lib/server/auth/getDevSession.test.mjs +0 -138
  77. package/lib/server/auth/session.js +0 -39
  78. package/manager/processes/warnAuthUrlPortMismatch.mjs +0 -47
  79. package/manager/processes/warnAuthUrlPortMismatch.test.mjs +0 -93
  80. package/src/routes/apiPage.js +0 -37
  81. package/src/routes/auth.test.mjs +0 -84
  82. package/src/routes/jsEnv.js +0 -30
package/client/Page.jsx CHANGED
@@ -20,7 +20,7 @@ import Client from '@lowdefy/client';
20
20
 
21
21
  import BuildErrorPage from '../lib/client/BuildErrorPage.jsx';
22
22
  import InstallingPluginsPage from '../lib/client/InstallingPluginsPage.jsx';
23
- import RestartingPage from '../lib/client/RestartingPage.jsx';
23
+ import RedirectingPage from '../lib/client/RedirectingPage.jsx';
24
24
  import usePageConfig from '../lib/client/utils/usePageConfig.js';
25
25
 
26
26
  const Page = ({
@@ -47,10 +47,22 @@ const Page = ({
47
47
  }
48
48
  }, [pageConfig?._warnings, lowdefy]);
49
49
 
50
+ // Full load to the sign-in page so it can return here after sign-in — an
51
+ // effect, not a fetcher side effect, so the redirect re-fires if the same
52
+ // cached result renders again.
53
+ useEffect(() => {
54
+ if (pageConfig?.authRedirect) {
55
+ window.location.assign(pageConfig.authRedirect);
56
+ }
57
+ }, [pageConfig?.authRedirect]);
58
+
50
59
  if (!pageConfig) {
51
60
  router.replace({ pathname: '/404' });
52
61
  return '';
53
62
  }
63
+ if (pageConfig.authRedirect) {
64
+ return <RedirectingPage redirect={pageConfig.authRedirect} />;
65
+ }
54
66
  if (pageConfig.buildError) {
55
67
  return (
56
68
  <BuildErrorPage
@@ -63,9 +75,6 @@ const Page = ({
63
75
  if (pageConfig.installing) {
64
76
  return <InstallingPluginsPage packages={pageConfig.packages} />;
65
77
  }
66
- if (resetContext.restarting) {
67
- return <RestartingPage />;
68
- }
69
78
 
70
79
  // Merge dynamic JS entries fetched after JIT build with the static jsMap
71
80
  const mergedJsMap = pageConfig._jsEntries ? { ...jsMap, ...pageConfig._jsEntries } : jsMap;
package/client/Reload.jsx CHANGED
@@ -25,6 +25,13 @@ import waitForRestartedServer from '../lib/client/utils/waitForRestartedServer.j
25
25
  const Reload = ({ children, basePath, lowdefy }) => {
26
26
  const [reset, setReset] = useState(false);
27
27
  const [restarting, setRestarting] = useState(false);
28
+ // reset is a one-shot boolean the engine lowers only after a page mounts
29
+ // (getContext.js) — while a page is suspended it stays true and setReset(true)
30
+ // bails out of re-rendering. The tick always changes, so every reload event
31
+ // re-invokes Routing's render prop, which re-reads reloadVersion and mints a
32
+ // fresh Suspense/SWR key — a suspended tab recovers instead of stranding on
33
+ // the building screen.
34
+ const [, setReloadTick] = useState(0);
28
35
  const mutateCache = useMutateCache(basePath);
29
36
  useEffect(() => {
30
37
  const sse = new EventSource(`${basePath}/api/reload`);
@@ -38,6 +45,7 @@ const Reload = ({ children, basePath, lowdefy }) => {
38
45
  lowdefy._internal.initialised = false;
39
46
  }
40
47
  setReset(true);
48
+ setReloadTick((tick) => tick + 1);
41
49
  console.log('Reloaded config.');
42
50
  }, 600);
43
51
  });
@@ -20,6 +20,7 @@ import Head from '@lowdefy/client/adapters/Head.js';
20
20
  import createLinkComponent from '@lowdefy/client/adapters/Link.js';
21
21
 
22
22
  import BuildingPage from '../lib/client/BuildingPage.jsx';
23
+ import RestartingPage from '../lib/client/RestartingPage.jsx';
23
24
  import FeedbackMount from './feedback/FeedbackMount.jsx';
24
25
  import Inspector from './Inspector.jsx';
25
26
  import OpenInEditorListener from './openInEditor/OpenInEditorListener.jsx';
@@ -75,29 +76,36 @@ function Routing({ auth, lowdefy, router }) {
75
76
  <FeedbackMount basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
76
77
  <OpenInEditorListener basePath={router.basePath} pageId={pageId} />
77
78
  <Reload basePath={router.basePath} lowdefy={lowdefy}>
78
- {(resetContext) => (
79
- <Suspense key={`${pageId}_${getReloadVersion()}`} fallback={<BuildingPage />}>
80
- <Page
81
- auth={auth}
82
- Components={{ Head, Link }}
83
- config={{
84
- rootConfig,
85
- }}
86
- jsMap={staticJsMap}
87
- lowdefy={lowdefy}
88
- pageId={pageId}
89
- resetContext={resetContext}
90
- router={router}
91
- types={{
92
- actions,
93
- blockMetas,
94
- blocks,
95
- icons,
96
- operators,
97
- }}
98
- />
99
- </Suspense>
100
- )}
79
+ {(resetContext) =>
80
+ // Rendered here, not in Page — Page sits below the Suspense boundary
81
+ // and cannot render anything while its config fetch is suspended, so
82
+ // a restarting server would present as "Building page..." forever.
83
+ resetContext.restarting ? (
84
+ <RestartingPage />
85
+ ) : (
86
+ <Suspense key={`${pageId}_${getReloadVersion()}`} fallback={<BuildingPage />}>
87
+ <Page
88
+ auth={auth}
89
+ Components={{ Head, Link }}
90
+ config={{
91
+ rootConfig,
92
+ }}
93
+ jsMap={staticJsMap}
94
+ lowdefy={lowdefy}
95
+ pageId={pageId}
96
+ resetContext={resetContext}
97
+ router={router}
98
+ types={{
99
+ actions,
100
+ blockMetas,
101
+ blocks,
102
+ icons,
103
+ operators,
104
+ }}
105
+ />
106
+ </Suspense>
107
+ )
108
+ }
101
109
  </Reload>
102
110
  </>
103
111
  );
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import React from 'react';
18
+
19
+ // Shown while the 401 sign-in redirect navigates. The link is the escape
20
+ // hatch for a dropped navigation - the tab must never depend on a single
21
+ // window.location.assign to leave this screen.
22
+ const RedirectingPage = ({ redirect }) => {
23
+ return (
24
+ <div
25
+ style={{
26
+ height: '100vh',
27
+ textAlign: 'center',
28
+ display: 'flex',
29
+ flexDirection: 'column',
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ backgroundColor: 'var(--ant-color-bg-layout)',
33
+ color: 'var(--ant-color-text)',
34
+ fontFamily:
35
+ "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
36
+ }}
37
+ >
38
+ <div
39
+ style={{
40
+ verticalAlign: 'middle',
41
+ display: 'inline-block',
42
+ }}
43
+ >
44
+ <h3>Redirecting to sign-in...</h3>
45
+ <p>
46
+ <a href={redirect} style={{ color: 'var(--ant-color-primary)' }}>
47
+ Continue to sign-in
48
+ </a>{' '}
49
+ if you are not redirected automatically.
50
+ </p>
51
+ </div>
52
+ </div>
53
+ );
54
+ };
55
+
56
+ export default RedirectingPage;
@@ -14,8 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- /* eslint-disable react/jsx-props-no-spreading */
18
-
19
17
  import React from 'react';
20
18
  import AuthConfigured from './AuthConfigured.jsx';
21
19
  import AuthNotConfigured from './AuthNotConfigured.js';
@@ -25,15 +23,15 @@ import { serializer } from '@lowdefy/helpers';
25
23
  // Client code imports the build JSON directly — Vite handles JSON imports;
26
24
  // the lib/build/*.js wrappers are server-only (they read from disk).
27
25
  // Deserialize to restore arrays from their ~arr build markers (providers
28
- // must be a real array for single-provider inference in createAuthMethods).
26
+ // must be a real array for provider lookups in createAuthMethods).
29
27
  import rawAuthConfig from '../../../build/auth.json';
30
28
 
31
29
  const authConfig = serializer.deserialize(rawAuthConfig);
32
30
 
33
- function Auth({ children, session }) {
31
+ function Auth({ children, user }) {
34
32
  if (authConfig.configured === true) {
35
33
  return (
36
- <AuthConfigured serverSession={session} authConfig={authConfig}>
34
+ <AuthConfigured serverUser={user} authConfig={authConfig}>
37
35
  {(auth) => children(auth)}
38
36
  </AuthConfigured>
39
37
  );
@@ -14,60 +14,207 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- /* eslint-disable react/jsx-props-no-spreading */
18
-
19
- import React, { useEffect, useRef } from 'react';
17
+ import React, { useEffect, useRef, useState } from 'react';
18
+ import { createAuthClient } from 'better-auth/react';
20
19
  import {
21
- authConfigManager,
22
- getSession,
23
- SessionProvider,
24
- signIn,
25
- signOut,
26
- useSession,
27
- } from '@hono/auth-js/react';
20
+ adminClient,
21
+ genericOAuthClient,
22
+ magicLinkClient,
23
+ organizationClient,
24
+ phoneNumberClient,
25
+ twoFactorClient,
26
+ } from 'better-auth/client/plugins';
27
+ import { oauthProviderClient } from '@better-auth/oauth-provider/client';
28
+ import { passkeyClient } from '@better-auth/passkey/client';
28
29
 
29
- import { serializer } from '@lowdefy/helpers';
30
+ import { normalizeCaller, serializer } from '@lowdefy/helpers';
30
31
 
31
32
  import rawLowdefyConfig from '../../../build/config.json';
32
33
 
33
34
  const lowdefyConfig = serializer.deserialize(rawLowdefyConfig);
34
35
 
35
- // @hono/auth-js/react configures its fetch paths through a module-level
36
- // manager instead of SessionProvider props.
37
- if (lowdefyConfig.basePath) {
38
- authConfigManager.setConfig({ basePath: `${lowdefyConfig.basePath}/api/auth` });
39
- }
36
+ const authClient = createAuthClient({
37
+ baseURL: `${window.location.origin}${lowdefyConfig.basePath ?? ''}/api/auth`,
38
+ plugins: [
39
+ adminClient(),
40
+ genericOAuthClient(),
41
+ magicLinkClient(),
42
+ oauthProviderClient(),
43
+ organizationClient(),
44
+ passkeyClient(),
45
+ phoneNumberClient(),
46
+ twoFactorClient(),
47
+ ],
48
+ });
40
49
 
41
- function Session({ children }) {
42
- const wasAuthenticated = useRef(false);
43
- const { data: session, status } = useSession();
44
- wasAuthenticated.current = wasAuthenticated.current || status === 'authenticated';
50
+ // UpdateSession owns session freshness - suppress BetterAuth's own
51
+ // signal-driven refetch on the calls that would otherwise fire one, so
52
+ // nothing competes with (and aborts) the refetch UpdateSession awaits.
53
+ // Only calls that mutate an existing session are suppressed - calls that
54
+ // can establish one (the sign-ins, and the two-factor, phone-number and
55
+ // passkey verifies) keep their signal: its refetch is what makes the store
56
+ // notice a login when no navigation follows.
57
+ // disableSignal silences all atomListeners for the call, including the
58
+ // organization plugin's org atoms - none are exposed to app config, so a
59
+ // future design exposing one must refresh it through its own action.
60
+ const sessionScoped = (params) => ({
61
+ ...params,
62
+ fetchOptions: { ...params?.fetchOptions, disableSignal: true },
63
+ });
64
+
65
+ // The server resolves the caller per request and embeds it in the page
66
+ // config, so the first render never flashes unauthenticated. The BetterAuth
67
+ // client store takes over once its session fetch settles.
68
+ //
69
+ // Roles and merged attributes resolve server-side from the active member row
70
+ // - the base session carries neither. The last server-resolved caller is
71
+ // held in state: while the session user is unchanged it stays authoritative
72
+ // for the fields the session does not carry, and UpdateSession refreshes it
73
+ // from /api/user after a change (e.g. SetActiveOrganization). Holding it in
74
+ // state, not a ref, re-renders Session when it changes so _user recomputes -
75
+ // the same reactive footing the session half already stands on.
76
+ //
77
+ // Only the session half is passed through normalizeCaller. BetterAuth's store
78
+ // returns camelCase keys whatever the columns are named, so untransformed it
79
+ // would sit emailVerified beside the resolved caller's email_verified on one
80
+ // object; anything arriving from the server is already snake_case.
81
+ function Session({ children, reloadSuppressedRef, serverUser }) {
82
+ const { data: session, isPending } = authClient.useSession();
83
+ const [resolvedUser, setResolvedUser] = useState(serverUser);
84
+ const wasAuthenticated = useRef(Boolean(serverUser));
45
85
 
46
86
  useEffect(() => {
47
- if (wasAuthenticated.current && status === 'unauthenticated') {
87
+ if (session) {
88
+ wasAuthenticated.current = true;
89
+ }
90
+ // Reload after sign-out (or session revocation) so the server can apply
91
+ // the page auth fork - a protected page redirects to the login page.
92
+ // A logout with a callbackUrl suppresses the reload - its own navigation
93
+ // would otherwise race this one.
94
+ if (wasAuthenticated.current && !isPending && !session && !reloadSuppressedRef.current) {
48
95
  window.location.reload();
49
96
  }
50
- }, [status]);
97
+ }, [session, isPending]);
51
98
 
52
- // If session is passed to SessionProvider from the server-rendered config
53
- // we won't have a loading state here, but unauthenticated first loads do.
54
- if (status === 'loading') {
55
- return '';
99
+ if (isPending) {
100
+ return children(resolvedUser, setResolvedUser);
101
+ }
102
+ if (!session?.user) {
103
+ return children(null, setResolvedUser);
104
+ }
105
+ const resolved = resolvedUser;
106
+ if (!resolved) {
107
+ return children({ roles: [], ...normalizeCaller(session.user) }, setResolvedUser);
108
+ }
109
+ if (resolved.id !== session.user.id) {
110
+ // The ref has not caught up with a changed session user - a sign-in as a
111
+ // different person lands between the session refetch and the /api/user
112
+ // result. Render the last resolved caller whole rather than mixing the new
113
+ // session user with the previous person's resolved fields, or falling back
114
+ // to a caller with no roles - blocks re-evaluate operators on render, so a
115
+ // role-guarded page would act on an empty role list. UpdateSession closes
116
+ // the window when it lands the new caller; a flow that changes the session
117
+ // user without chaining it leaves the previous caller rendered until the
118
+ // next page load.
119
+ return children(resolved, setResolvedUser);
56
120
  }
57
- return children(session);
121
+ // _user is one object with one meaning on both sides: the resolved caller is
122
+ // spread whole, so every field resolveAuthentication emits is readable in app
123
+ // config without this file naming it. session.user is the floor - the client
124
+ // store may hold a fresher one than the resolved state, and the resolved
125
+ // object wins wherever both carry a key.
126
+ const user = { ...normalizeCaller(session.user), ...resolved };
127
+ return children(user, setResolvedUser);
58
128
  }
59
129
 
60
- function AuthConfigured({ authConfig, children, serverSession }) {
61
- const auth = { authConfig, getSession, signIn, signOut };
130
+ function AuthConfigured({ authConfig, children, serverUser }) {
131
+ const reloadSuppressedRef = useRef(false);
132
+ const auth = {
133
+ authConfig,
134
+ getSession: ({ disableCookieCache } = {}) =>
135
+ authClient.getSession(disableCookieCache ? { query: { disableCookieCache: true } } : {}),
136
+ // Refetches the session through the session atom - the store's only
137
+ // writer - and resolves only after the store is written. fetchSession
138
+ // returns undefined and never rejects (failures are written into the
139
+ // atom), so the atom's own { data, error } is read back and returned,
140
+ // keeping unwrap working and surfacing a failed refresh to the action.
141
+ refreshSession: async ({ disableCookieCache } = {}) => {
142
+ const sessionAtom = authClient.$store.atoms.session;
143
+ await sessionAtom
144
+ .get()
145
+ .refetch(disableCookieCache ? { query: { disableCookieCache: true } } : undefined);
146
+ const { data, error } = sessionAtom.get();
147
+ return { data, error };
148
+ },
149
+ // The server-resolved caller - roles from the active member row and the
150
+ // merged attributes bag - for re-syncing after session changes.
151
+ getResolvedUser: async () => {
152
+ const response = await fetch(`${lowdefyConfig.basePath ?? ''}/api/user`, {
153
+ credentials: 'same-origin',
154
+ });
155
+ if (!response.ok) {
156
+ // /api/user itself always answers 200 { user } - user: null when no
157
+ // caller is admitted, which updateSession branches on. A non-OK
158
+ // response is a transport failure (gateway error page, 5xx) with no
159
+ // parsable body.
160
+ throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
161
+ }
162
+ return response.json();
163
+ },
164
+ suppressSignOutReload: () => {
165
+ reloadSuppressedRef.current = true;
166
+ },
167
+ acceptInvitation: (params) => authClient.organization.acceptInvitation(sessionScoped(params)),
168
+ // addPasskey runs the WebAuthn browser ceremony itself - options fetch,
169
+ // authenticator prompt, verification.
170
+ addPasskey: (params) => authClient.passkey.addPasskey(params),
171
+ changePassword: (params) => authClient.changePassword(sessionScoped(params)),
172
+ deletePasskey: (params) => authClient.passkey.deletePasskey(params),
173
+ updatePasskey: (params) => authClient.passkey.updatePasskey(params),
174
+ leaveOrganization: (params) => authClient.organization.leave(sessionScoped(params)),
175
+ // The caller's memberships from the org plugin, keyed on the session
176
+ // alone - not the active organization. sessionScoped so the list read
177
+ // does not also fire the org-list atom's own refetch of the same route.
178
+ listOrganizations: () => authClient.organization.list(sessionScoped()),
179
+ // POST /oauth2/consent. The signed authorization query is not passed
180
+ // here - the oauthProviderClient fetch plugin stamps it onto the body as
181
+ // oauth_query from window.location.search, so the call must run while
182
+ // the page still holds the query the oauth-provider redirect arrived
183
+ // with.
184
+ oauth2Consent: (params) => authClient.oauth2.consent(params),
185
+ phoneNumberRequestPasswordReset: (params) =>
186
+ authClient.phoneNumber.requestPasswordReset(params),
187
+ phoneNumberResetPassword: (params) => authClient.phoneNumber.resetPassword(params),
188
+ phoneNumberSendOtp: (params) => authClient.phoneNumber.sendOtp(params),
189
+ phoneNumberVerify: (params) => authClient.phoneNumber.verify(params),
190
+ requestPasswordReset: (params) => authClient.requestPasswordReset(params),
191
+ resetPassword: (params) => authClient.resetPassword(params),
192
+ revokeOtherSessions: () => authClient.revokeOtherSessions(sessionScoped()),
193
+ sendVerificationEmail: (params) => authClient.sendVerificationEmail(params),
194
+ setActiveOrganization: (params) => authClient.organization.setActive(sessionScoped(params)),
195
+ signInEmail: (params) => authClient.signIn.email(params),
196
+ signInMagicLink: (params) => authClient.signIn.magicLink(params),
197
+ signInOauth2: (params) => authClient.signIn.oauth2(params),
198
+ signInPasskey: (params) => authClient.signIn.passkey(params),
199
+ signInPhoneNumber: (params) => authClient.signIn.phoneNumber(params),
200
+ signInSocial: (params) => authClient.signIn.social(params),
201
+ signOut: () => authClient.signOut(),
202
+ signUpEmail: (params) => authClient.signUp.email(params),
203
+ twoFactorDisable: (params) => authClient.twoFactor.disable(sessionScoped(params)),
204
+ twoFactorEnable: (params) => authClient.twoFactor.enable(sessionScoped(params)),
205
+ twoFactorGenerateBackupCodes: (params) =>
206
+ authClient.twoFactor.generateBackupCodes(sessionScoped(params)),
207
+ twoFactorVerifyBackupCode: (params) => authClient.twoFactor.verifyBackupCode(params),
208
+ twoFactorVerifyTotp: (params) => authClient.twoFactor.verifyTotp(params),
209
+ };
62
210
  return (
63
- <SessionProvider session={serverSession}>
64
- <Session>
65
- {(session) => {
66
- auth.session = session;
67
- return children(auth);
68
- }}
69
- </Session>
70
- </SessionProvider>
211
+ <Session reloadSuppressedRef={reloadSuppressedRef} serverUser={serverUser}>
212
+ {(user, setResolvedUser) => {
213
+ auth.user = user;
214
+ auth.updateResolvedUser = (resolved) => setResolvedUser(resolved);
215
+ return children(auth);
216
+ }}
217
+ </Session>
71
218
  );
72
219
  }
73
220
 
@@ -13,7 +13,6 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- /* eslint-disable react/jsx-props-no-spreading */
17
16
 
18
17
  function authNotConfigured() {
19
18
  throw new Error('Auth not configured.');
@@ -22,9 +21,31 @@ function authNotConfigured() {
22
21
  function AuthNotConfigured({ authConfig, children }) {
23
22
  const auth = {
24
23
  authConfig,
24
+ user: null,
25
+ acceptInvitation: authNotConfigured,
26
+ addPasskey: authNotConfigured,
27
+ changePassword: authNotConfigured,
28
+ deletePasskey: authNotConfigured,
29
+ updatePasskey: authNotConfigured,
30
+ getResolvedUser: authNotConfigured,
25
31
  getSession: authNotConfigured,
26
- signIn: authNotConfigured,
32
+ leaveOrganization: authNotConfigured,
33
+ requestPasswordReset: authNotConfigured,
34
+ resetPassword: authNotConfigured,
35
+ revokeOtherSessions: authNotConfigured,
36
+ sendVerificationEmail: authNotConfigured,
37
+ setActiveOrganization: authNotConfigured,
38
+ signInEmail: authNotConfigured,
39
+ signInMagicLink: authNotConfigured,
40
+ signInOauth2: authNotConfigured,
41
+ signInSocial: authNotConfigured,
27
42
  signOut: authNotConfigured,
43
+ signUpEmail: authNotConfigured,
44
+ twoFactorDisable: authNotConfigured,
45
+ twoFactorEnable: authNotConfigured,
46
+ twoFactorGenerateBackupCodes: authNotConfigured,
47
+ twoFactorVerifyBackupCode: authNotConfigured,
48
+ twoFactorVerifyTotp: authNotConfigured,
28
49
  };
29
50
 
30
51
  return children(auth);
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { readdir, readFile } from 'node:fs/promises';
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ const devAuthDir = path.dirname(fileURLToPath(import.meta.url));
22
+ const prodAuthDir = path.resolve(devAuthDir, '../../../../server/lib/client/auth');
23
+
24
+ // The dev and prod server templates each carry their own copy of the auth
25
+ // components, kept in sync by hand. A change applied to one and not the
26
+ // other ships dev-only or prod-only - the app then behaves differently
27
+ // between lowdefy dev and a production build, which no unit test of either
28
+ // copy can catch.
29
+ test('the auth client templates are byte-identical between server and server-dev', async () => {
30
+ const isTemplate = (file) => !file.includes('.test.');
31
+ const devFiles = (await readdir(devAuthDir)).filter(isTemplate).sort();
32
+ const prodFiles = (await readdir(prodAuthDir)).filter(isTemplate).sort();
33
+ expect(prodFiles).toEqual(devFiles);
34
+ for (const file of devFiles) {
35
+ const dev = await readFile(path.join(devAuthDir, file), 'utf8');
36
+ const prod = await readFile(path.join(prodAuthDir, file), 'utf8');
37
+ // Compared per file so a failure names the file that diverged.
38
+ expect({ file, content: prod }).toEqual({ file, content: dev });
39
+ }
40
+ });