@softr/sdk 1.15.1 → 1.16.0-alpha.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.16.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - Log in with Softr: workspace members sign in to the app with their Softr account. `softrSignInHref(returnPath?)` gives the link, and `AuthOptions.softr` tells the login page to show the button. A failed Softr login lands on the SSO page with `method=softr`, the login redirect param and an `error`, which is `softr-rejected` (type `SoftrLoginError`) when Softr did not let the account in, or `softr-sso-account` when the account signs in with the single sign-on that the app also offers. Action: on the SSO page, when `method` is `softr`, link "Try again" to `softrSignInHref(toReturnPath(location).href)`.
8
+
3
9
  ## 1.15.1
4
10
 
5
11
  ### Patch Changes
@@ -77,6 +77,8 @@ type AuthOptions = {
77
77
  sso: {
78
78
  type: "SAML" | "OPEN_ID";
79
79
  } | null;
80
+ /** Sign-in with a Softr Studio account: a link to `softrSignInHref`. */
81
+ softr: boolean;
80
82
  /** `auth.signUp`, then `auth.confirmSignUp` */
81
83
  signUp: boolean;
82
84
  /** The builder asked for strong passwords whenever a visitor sets one. */
@@ -132,6 +132,7 @@ const getAuthSettings = createServerFn({ method: "GET" }).handler(async () => {
132
132
  magicLink: on("MAGIC_LINK"),
133
133
  google: on("GOOGLE") && clientId ? { clientId } : null,
134
134
  sso: on("SSO") && raw.sso?.type ? { type: raw.sso.type } : null,
135
+ softr: raw.loginEnabled && raw.softrLogin === true,
135
136
  signUp: raw.loginEnabled && (raw.signUpPolicy === "OPEN_TO_PUBLIC" || raw.signUpPolicy === "DOMAIN_RESTRICTED"),
136
137
  strongPasswords: on("EMAIL") && (raw.emailAuth?.strongPasswords ?? false)
137
138
  };
@@ -39,6 +39,7 @@ declare const authSettingsSchema: z.ZodObject<{
39
39
  OPEN_ID: "OPEN_ID";
40
40
  }>>;
41
41
  }, z.core.$strip>>;
42
+ softrLogin: z.ZodOptional<z.ZodBoolean>;
42
43
  }, z.core.$strip>;
43
44
  type AuthSettings = z.infer<typeof authSettingsSchema>;
44
45
  //#endregion
@@ -29,7 +29,8 @@ const authSettingsSchema = z.object({
29
29
  clientId: z.string().nullable(),
30
30
  userType: z.enum(["INTERNAL", "EXTERNAL"]).nullable()
31
31
  }).nullable(),
32
- sso: z.object({ type: z.enum(["SAML", "OPEN_ID"]).nullable() }).nullable()
32
+ sso: z.object({ type: z.enum(["SAML", "OPEN_ID"]).nullable() }).nullable(),
33
+ softrLogin: z.boolean().optional()
33
34
  });
34
35
  function makePlatform(applicationId) {
35
36
  const aliases = Object.entries(softrConfig().user?.properties ?? {});
@@ -216,6 +217,18 @@ function makePlatform(applicationId) {
216
217
  method: "POST",
217
218
  json: body
218
219
  }, ssoSignInSchema),
220
+ softrLoginStart: (body) => request(`/v1/vibe/applications/${applicationId}/users/softr-login/start`, {
221
+ method: "POST",
222
+ json: body
223
+ }, z.object({
224
+ bindingToken: z.string(),
225
+ returnPath: z.string(),
226
+ redirectUrl: z.string()
227
+ })),
228
+ signInWithSoftr: (body) => request(`/v1/vibe/applications/${applicationId}/users/tokens/with-softr${withAttributes}`, {
229
+ method: "POST",
230
+ json: body
231
+ }, ssoSignInSchema),
219
232
  ssoDiscover: (body) => request(`/v1/vibe/applications/${applicationId}/users/sso/discover`, {
220
233
  method: "POST",
221
234
  json: body
@@ -14,11 +14,34 @@ import "@tanstack/react-start";
14
14
  * <a href={ssoSignInHref(toReturnPath(location).href)}>Continue with SSO</a>
15
15
  */
16
16
  declare function ssoSignInHref(returnPath?: string): string;
17
+ /**
18
+ * Where a link or button sends a visitor to sign in with their Softr Studio
19
+ * account. They come back to `returnPath` once signed in. Without one, they
20
+ * land where `auth.guard.alreadyAuthenticated` in softr.json points, as after
21
+ * any sign-in.
22
+ *
23
+ * A full page load, not a router navigation: the visitor leaves the app for
24
+ * Softr Studio.
25
+ *
26
+ * @example
27
+ * <a href={softrSignInHref(toReturnPath(location).href)}>Continue with Softr</a>
28
+ */
29
+ declare function softrSignInHref(returnPath?: string): string;
17
30
  /**
18
31
  * Why single sign-on did not finish, as the `error` search param of the SSO
19
32
  * page. Never the platform's own message: that is for the builder, and it would
20
33
  * sit in the visitor's address bar.
21
34
  */
22
35
  type SsoError = "host" | "idp" | "not-enabled" | "sign-up-disabled" | "restricted" | "expired" | "failed";
36
+ /**
37
+ * The extra reasons a sign-in with a Softr Studio account can fail, besides
38
+ * the {@link SsoError} values. `softr-rejected`: Softr did not let this
39
+ * account in. `softr-sso-account`: the account signs in with single sign-on,
40
+ * which the app also offers. It is a separate type so that an existing
41
+ * `Record<SsoError, ...>` keeps compiling.
42
+ *
43
+ * The SSO page gets it as its `error` search param, with `method=softr`.
44
+ */
45
+ type SoftrLoginError = "softr-rejected" | "softr-sso-account";
23
46
  //#endregion
24
- export { SsoError, ssoSignInHref };
47
+ export { SoftrLoginError, SsoError, softrSignInHref, ssoSignInHref };
package/dist/auth/sso.js CHANGED
@@ -11,6 +11,8 @@ import { createMiddleware } from "@tanstack/react-start";
11
11
 
12
12
  //#region src/auth/sso.ts
13
13
  const START_PATH = "/_softr/sso/start";
14
+ const SOFTR_START_PATH = "/_softr/softr-login/start";
15
+ const SOFTR_CALLBACK_PATH = "/_softr/softr-login/callback";
14
16
  const OPEN_ID_CALLBACK_PATH = "/open-id/code";
15
17
  const SAML_CALLBACK_PATH = "/saml/SSO";
16
18
  const DEFAULT_SSO_PATH = "/sso-authentication";
@@ -29,12 +31,28 @@ function ssoSignInHref(returnPath) {
29
31
  return returnPath ? `${START_PATH}?return=${encodeURIComponent(returnPath)}` : START_PATH;
30
32
  }
31
33
  /**
34
+ * Where a link or button sends a visitor to sign in with their Softr Studio
35
+ * account. They come back to `returnPath` once signed in. Without one, they
36
+ * land where `auth.guard.alreadyAuthenticated` in softr.json points, as after
37
+ * any sign-in.
38
+ *
39
+ * A full page load, not a router navigation: the visitor leaves the app for
40
+ * Softr Studio.
41
+ *
42
+ * @example
43
+ * <a href={softrSignInHref(toReturnPath(location).href)}>Continue with Softr</a>
44
+ */
45
+ function softrSignInHref(returnPath) {
46
+ return returnPath ? `${SOFTR_START_PATH}?return=${encodeURIComponent(returnPath)}` : SOFTR_START_PATH;
47
+ }
48
+ /**
32
49
  * Starts single sign-on and finishes it when the identity provider answers.
33
- * Every other request passes through.
50
+ * It does the same for a sign-in with a Softr Studio account, where Studio is
51
+ * the identity provider. Every other request passes through.
34
52
  *
35
53
  * The start is a GET the visitor's browser makes, so a link can begin it. The
36
54
  * identity provider answers OpenID Connect with a redirect, and SAML with a
37
- * form it posts from its own site.
55
+ * form it posts from its own site. Studio answers with a redirect.
38
56
  */
39
57
  function ssoMiddleware() {
40
58
  return createMiddleware({ type: "request" }).server(async ({ next, request, pathname }) => {
@@ -59,6 +77,30 @@ function ssoMiddleware() {
59
77
  ...binding
60
78
  }), binding.returnPath);
61
79
  }
80
+ case SOFTR_START_PATH:
81
+ if (request.method !== "GET") return methodNotAllowed("GET");
82
+ return await softrStart(new URL(request.url));
83
+ case SOFTR_CALLBACK_PATH: {
84
+ if (request.method !== "GET") return methodNotAllowed("GET");
85
+ const url = new URL(request.url);
86
+ const code = url.searchParams.get("code");
87
+ const binding = readSsoBinding();
88
+ clearSsoBinding();
89
+ if (code === null) return toSsoPage({
90
+ error: "failed",
91
+ returnPath: binding?.returnPath,
92
+ method: "softr"
93
+ });
94
+ if (binding === null) return toSsoPage({
95
+ error: "expired",
96
+ method: "softr"
97
+ });
98
+ return await finish(await platform().signInWithSoftr({
99
+ code,
100
+ state: url.searchParams.get("state") ?? "",
101
+ ...binding
102
+ }), binding.returnPath, "softr");
103
+ }
62
104
  case SAML_CALLBACK_PATH: {
63
105
  if (request.method !== "POST") return methodNotAllowed("POST");
64
106
  const form = await request.formData().catch(() => null);
@@ -111,14 +153,39 @@ async function start(url) {
111
153
  writeCookies([binding]);
112
154
  return samlForm(started.formAction, started.samlRequest, started.relayState);
113
155
  }
156
+ async function softrStart(url) {
157
+ const returnPath = resolveReturnPath(url.searchParams.get("return"));
158
+ const result = await platform().softrLoginStart({
159
+ origin: url.origin,
160
+ returnPath
161
+ });
162
+ if (!result.ok) return toSsoPage({
163
+ ...failure(result),
164
+ returnPath,
165
+ method: "softr"
166
+ });
167
+ const started = result.data;
168
+ writeCookies([makeSsoBindingCookie({
169
+ bindingToken: started.bindingToken,
170
+ returnPath: started.returnPath
171
+ })]);
172
+ return new Response(null, {
173
+ status: 302,
174
+ headers: {
175
+ location: started.redirectUrl,
176
+ "cache-control": "no-store"
177
+ }
178
+ });
179
+ }
114
180
  /**
115
181
  * `startedFor` is where the visitor wanted to go, so a retry after a failure
116
182
  * gets there.
117
183
  */
118
- async function finish(result, startedFor) {
184
+ async function finish(result, startedFor, method = "sso") {
119
185
  if (!result.ok) return toSsoPage({
120
186
  ...failure(result),
121
- returnPath: startedFor
187
+ returnPath: startedFor,
188
+ method
122
189
  });
123
190
  const { result: signIn, returnPath } = result.data;
124
191
  if (signIn.status === "MFA_REQUIRED") {
@@ -150,6 +217,8 @@ function failure(result) {
150
217
  case "USER_DEACTIVATED":
151
218
  case "SIGN_IN_RESTRICTED": return { error: "restricted" };
152
219
  case "SSO_BINDING_INVALID": return { error: "expired" };
220
+ case "SOFTR_LOGIN_REJECTED": return { error: "softr-rejected" };
221
+ case "SOFTR_LOGIN_SSO_ACCOUNT": return { error: "softr-sso-account" };
153
222
  default:
154
223
  logger.warn(`Single sign-on failed with ${result.status} ${code ?? "(no code)"}: ${result.message}`);
155
224
  return { error: "failed" };
@@ -164,8 +233,10 @@ function failure(result) {
164
233
  function toSsoPage(search) {
165
234
  const { routes } = softrConfig().auth;
166
235
  const params = new URLSearchParams();
167
- if ("error" in search) params.set("error", search.error);
168
- else params.set("authenticator", search.authenticator);
236
+ if ("error" in search) {
237
+ params.set("error", search.error);
238
+ if (search.method === "softr") params.set("method", "softr");
239
+ } else params.set("authenticator", search.authenticator);
169
240
  if (search.returnPath !== void 0) params.set(routes.login.redirectParam, resolveReturnPath(search.returnPath));
170
241
  return seeOther(`${routes.sso?.path ?? DEFAULT_SSO_PATH}?${params}`);
171
242
  }
@@ -217,4 +288,4 @@ function platform() {
217
288
  }
218
289
 
219
290
  //#endregion
220
- export { ssoMiddleware, ssoSignInHref };
291
+ export { softrSignInHref, ssoMiddleware, ssoSignInHref };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
11
11
  import { Page, PageSettings, definePage, pageHead } from "./route/page.js";
12
12
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
13
13
  import { toReturnPath } from "./auth/returnPath.js";
14
- import { SsoError, ssoSignInHref } from "./auth/sso.js";
14
+ import { SoftrLoginError, SsoError, softrSignInHref, ssoSignInHref } from "./auth/sso.js";
15
15
  import { AuthOptions, AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
16
16
  import { useIdleTimeout } from "./auth/idle-timeout.js";
17
17
  import { Tool, ToolDefinition, defineTool } from "./tool.js";
@@ -25,4 +25,4 @@ import { DefaultErrorOverlay } from "./default-error-overlay.js";
25
25
  import { Audience } from "./route/audience.js";
26
26
  import { Logo, LogoFile } from "./softr-config.schema.js";
27
27
  import { getLogo } from "./softr-config.js";
28
- export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailErrorCode, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Logo, type LogoFile, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type Tool, type ToolDefinition, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
28
+ export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailErrorCode, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Logo, type LogoFile, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, type SoftrLoginError, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type Tool, type ToolDefinition, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, softrSignInHref, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
5
5
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
6
6
  import { definePage, pageHead } from "./route/page.js";
7
7
  import { toReturnPath } from "./auth/returnPath.js";
8
- import { ssoSignInHref } from "./auth/sso.js";
8
+ import { softrSignInHref, ssoSignInHref } from "./auth/sso.js";
9
9
  import { FormattedDate, FormattingScope, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
10
10
  import { SoftrPwaHead, usePwaInstall } from "./pwa.js";
11
11
  import { usePushNotifications } from "./push.js";
@@ -19,4 +19,4 @@ import { useUserTimezone } from "./timezone.js";
19
19
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
20
20
  import { Audience } from "./route/audience.js";
21
21
 
22
- export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
22
+ export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, softrSignInHref, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.15.1";
2
+ var version = "1.16.0-alpha.2";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.15.1",
3
+ "version": "1.16.0-alpha.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: core
13
13
  library: softr-sdk
14
- library_version: 1.15.1
14
+ library_version: 1.16.0-alpha.2
15
15
  ---
16
16
 
17
17
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.15.1
16
+ library_version: 1.16.0-alpha.2
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.15.1
13
+ library_version: 1.16.0-alpha.2
14
14
  ---
15
15
 
16
16
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -176,6 +176,7 @@ Each field names the `auth` call it unlocks:
176
176
  | `emailCode` | sign-in with a code, `auth.sendSignInCode` |
177
177
  | `magicLink` | the route that calls `auth.signInWithMagicLink` |
178
178
  | `google` | a Google button started with `google.clientId`. `null` means no Google. Never hardcode a client id. |
179
+ | `softr` | a "Continue with Softr" link to `softrSignInHref(...)`, for people who sign in with their Softr Studio account. See [references/single-sign-on.md](./references/single-sign-on.md#log-in-with-softr) |
179
180
  | `signUp` | sign-up, `auth.signUp` |
180
181
  | `strongPasswords` | the strong-password rules, on every form that sets a new password. Check the password against them before submitting. |
181
182
 
@@ -26,6 +26,7 @@ When single sign-on needs more from the visitor, or fails, they come back to the
26
26
  | --- | --- | --- |
27
27
  | `authenticator` | `'verify'`, `'setup'` or `'setupOptional'`: the app asks for an authenticator app as well | the second-factor step, as for `authenticatorRequired` and its `step`. Finish with the same calls, then `toReturnPath(location)` |
28
28
  | `error` | why it did not finish, one of the codes below | a message, a "Try again" link to `ssoSignInHref(toReturnPath(location).href)`, and a link to the login page that keeps the redirect param, so either way the visitor ends where they wanted |
29
+ | `method` | `'softr'` when [log in with Softr](#log-in-with-softr) failed, absent for single sign-on | the "Try again" link goes to `softrSignInHref(toReturnPath(location).href)` instead |
29
30
 
30
31
  | `error` | Means |
31
32
  | --- | --- |
@@ -36,6 +37,8 @@ When single sign-on needs more from the visitor, or fails, they come back to the
36
37
  | `restricted` | The account is deactivated, or the app has no room for another user |
37
38
  | `expired` | It took too long, another tab started a newer sign-in, or the sign-in started at the identity provider rather than in the app |
38
39
  | `failed` | Anything else |
40
+ | `softr-rejected` | Log in with Softr only: Softr did not let this account in |
41
+ | `softr-sso-account` | Log in with Softr only: this account signs in with single sign-on. Link to `ssoSignInHref(toReturnPath(location).href)` |
39
42
 
40
43
  With neither param, redirect to `toReturnPath(location)`.
41
44
 
@@ -48,3 +51,25 @@ Three ways to put it on the login page. Build the one the builder asks for:
48
51
  1. **A button**, as above, next to the other methods. The default.
49
52
  2. **Email first.** Ask for the email, then call `auth.discoverSso({ email })` from a server function. It answers a `Result` of `{ sso: boolean }`, decided by the email's domain alone, and fails only with `tooManyAttempts`. On `sso: true` send the visitor to `ssoSignInHref(...)` with `window.location.assign`, otherwise carry on with the password or code step. Never hardcode the domains: the builder changes them in Softr, and the app would not follow.
50
53
  3. **Straight to the identity provider** when single sign-on is the only method: send the visitor to `ssoSignInHref(...)` as the login page loads. Skip it when the login page has a `signedOut` search param, or the visitor is signed straight back in after signing out, since the identity provider still knows them. The sign-out server function adds it: `throw redirect({ to: '/login', search: { signedOut: true } })`, and so does the login link on the single sign-on page, or an error there sends the visitor to the identity provider and back to the same error. Keep the button on the page for that case.
54
+
55
+ ## Log in with Softr
56
+
57
+ People in the audience the builder chose in Softr sign in with their Softr Studio account. Softr Studio is their identity provider, so it works like single sign-on: a link starts it, and there is no server function to write.
58
+
59
+ ```tsx
60
+ import { useLocation } from '@tanstack/react-router'
61
+ import { softrSignInHref, toReturnPath, useAuthSettings } from '@softr/sdk'
62
+
63
+ const options = useAuthSettings()
64
+ const location = useLocation()
65
+
66
+ {options.softr ? (
67
+ <Button nativeButton={false} render={<a href={softrSignInHref(toReturnPath(location).href)} />}>
68
+ Continue with Softr
69
+ </Button>
70
+ ) : null}
71
+ ```
72
+
73
+ The same rules as `ssoSignInHref` apply: a plain `<a href>`, a return path on this app, or none. It comes back to the same page as single sign-on, with `method=softr` next to `error`, and with the same `authenticator` step. The other codes above can also come with `method=softr`, so name the method from `method`, not "single sign-on". Show `softr-rejected` as "you do not have access to this app", and offer no "Try again": only the app owner can change it.
74
+
75
+ An app whose only way in is log in with Softr still has a login page, with the button on it. Do not send visitors to Softr as the page loads.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.15.1
13
+ library_version: 1.16.0-alpha.2
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.15.1
14
+ library_version: 1.16.0-alpha.2
15
15
  ---
16
16
 
17
17
  # The current user
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 1.15.1
15
+ library_version: 1.16.0-alpha.2
16
16
  ---
17
17
 
18
18
  **Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.15.1
10
+ library_version: 1.16.0-alpha.2
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.15.1
11
+ library_version: 1.16.0-alpha.2
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -93,7 +93,7 @@ For a page or an area, wrap it in `FormattingScope`. Every `FormattedDate` and `
93
93
  For one value, pass `timeZone`. It wins over a scope. Use it for an event that shows in its own zone, from a record field or a DATETIME field whose `options` in the datasource schema name a `timezone` and a `timezoneType` other than `LOCAL`.
94
94
 
95
95
  ```tsx
96
- <FormattedDate value={event.fields.starts} time timeZone={event.fields.zone ?? undefined} />
96
+ <FormattedDate value={event.fields.starts} time timeZone={event.fields.zone} />
97
97
  ```
98
98
 
99
99
  Say which zone a fixed-zone time is in, so a visitor elsewhere does not read it as theirs: add `timeZoneName: 'short'` to `parts`, or write the zone next to it. An unknown zone or locale is ignored with a warning, so a bad record never breaks the page.
@@ -108,7 +108,7 @@ function BugRow({ bug }: { bug: Bug }) {
108
108
  return (
109
109
  <li title={`Created ${formatDateTime(bug.fields.created, formatting)}`}>
110
110
  {bug.fields.title}
111
- <span>{bug.fields.votes === null ? '—' : formatNumber(bug.fields.votes, formatting)}</span>
111
+ <span>{formatNumber(bug.fields.votes, formatting)}</span>
112
112
  <FormattedDate value={bug.fields.created} dateStyle="medium" />
113
113
  </li>
114
114
  )
@@ -166,11 +166,10 @@ For a shape the helpers do not give, such as a range (`Oct 6 – 8`), use `Intl`
166
166
 
167
167
  ```tsx
168
168
  const formatting = useFormatting()
169
- const { starts, ends } = trip.fields
170
- const range = formatting.timeZone === null || starts === null || ends === null
169
+ const range = formatting.timeZone === null
171
170
  ? null
172
171
  : new Intl.DateTimeFormat(formatting.dateLocale, { month: 'short', day: 'numeric', timeZone: formatting.timeZone })
173
- .formatRange(new Date(starts), new Date(ends))
172
+ .formatRange(new Date(trip.fields.starts), new Date(trip.fields.ends))
174
173
  ```
175
174
 
176
175
  ### Relative time and now
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.15.1
10
+ library_version: 1.16.0-alpha.2
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.15.1
14
+ library_version: 1.16.0-alpha.2
15
15
  ---
16
16
 
17
17
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP. The tools you hand it come from `defineTool`, also on `@softr/sdk`, and call the same server logic the pages do.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.15.1
12
+ library_version: 1.16.0-alpha.2
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.15.1
13
+ library_version: 1.16.0-alpha.2
14
14
  ---
15
15
 
16
16
  # Installing the app
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.15.1
13
+ library_version: 1.16.0-alpha.2
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -202,11 +202,9 @@ const projectDetail = defineQuery({
202
202
  })
203
203
 
204
204
  const project = await ds.get(projectDetail, { id })
205
- if (project === null) throw notFound()
206
- const status = project.fields.status
207
205
  await ds.update(updateProject, {
208
206
  id,
209
- data: { status: status === null ? null : { id: status.id } },
207
+ data: { status: { id: project.fields.status.id } },
210
208
  })
211
209
  ```
212
210
 
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.15.1
14
+ library_version: 1.16.0-alpha.2
15
15
  ---
16
16
 
17
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.15.1
12
+ library_version: 1.16.0-alpha.2
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.15.1
12
+ library_version: 1.16.0-alpha.2
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.15.1
12
+ library_version: 1.16.0-alpha.2
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.