UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

42 lines (40 loc) • 1.37 kB
import { z } from "zod"; //#region src/auth/methods/utils.ts function authError(code, message) { return { success: false, error: { code, message } }; } const errorBodySchema = z.object({ code: z.string() }); /** * True when Softr refused because the plan of the app's workspace has no room * for this user. It arrives as a 400, like a wrong code, so the status cannot * tell them apart. */ function isUserLimitReached(result) { const body = errorBodySchema.safeParse(result.body); return body.success && body.data.code === "USER_LIMIT_REACHED"; } /** * True when Softr refused because the plan of the app's workspace does not * include this way to sign in: Google sign-in or the one-time email code, as * after a downgrade. */ function isNotInPlan(result) { const body = errorBodySchema.safeParse(result.body); return body.success && (body.data.code === "GOOGLE_NOT_IN_PLAN" || body.data.code === "EMAIL_CODE_NOT_IN_PLAN"); } /** * True when Softr refused because the visitor owes an authenticator app step * that the plan of the app's workspace does not include, as after a downgrade. */ function isAuthenticatorNotInPlan(result) { const body = errorBodySchema.safeParse(result.body); return body.success && body.data.code === "AUTHENTICATOR_NOT_IN_PLAN"; } //#endregion export { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached };