@softure-ai/auth 0.0.0-stage → 0.1.5

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 (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +381 -2
  3. package/dist/contract.d.ts +44 -0
  4. package/dist/contract.d.ts.map +1 -0
  5. package/dist/contract.js +2 -0
  6. package/dist/contract.js.map +1 -0
  7. package/dist/index.d.ts +188 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +84 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/mailing/index.d.ts +2 -0
  12. package/dist/mailing/index.d.ts.map +1 -0
  13. package/dist/mailing/index.js +4 -0
  14. package/dist/mailing/index.js.map +1 -0
  15. package/dist/mailing/reset-mail.d.ts +27 -0
  16. package/dist/mailing/reset-mail.d.ts.map +1 -0
  17. package/dist/mailing/reset-mail.js +55 -0
  18. package/dist/mailing/reset-mail.js.map +1 -0
  19. package/dist/messages/en.d.ts +97 -0
  20. package/dist/messages/en.d.ts.map +1 -0
  21. package/dist/messages/en.js +92 -0
  22. package/dist/messages/en.js.map +1 -0
  23. package/dist/messages/index.d.ts +199 -0
  24. package/dist/messages/index.d.ts.map +1 -0
  25. package/dist/messages/index.js +11 -0
  26. package/dist/messages/index.js.map +1 -0
  27. package/dist/messages/pl.d.ts +3 -0
  28. package/dist/messages/pl.d.ts.map +1 -0
  29. package/dist/messages/pl.js +91 -0
  30. package/dist/messages/pl.js.map +1 -0
  31. package/dist/next/actions.d.ts +19 -0
  32. package/dist/next/actions.d.ts.map +1 -0
  33. package/dist/next/actions.js +210 -0
  34. package/dist/next/actions.js.map +1 -0
  35. package/dist/next/context.d.ts +4 -0
  36. package/dist/next/context.d.ts.map +1 -0
  37. package/dist/next/context.js +13 -0
  38. package/dist/next/context.js.map +1 -0
  39. package/dist/next/current-user.d.ts +34 -0
  40. package/dist/next/current-user.d.ts.map +1 -0
  41. package/dist/next/current-user.js +77 -0
  42. package/dist/next/current-user.js.map +1 -0
  43. package/dist/next/index.d.ts +8 -0
  44. package/dist/next/index.d.ts.map +1 -0
  45. package/dist/next/index.js +9 -0
  46. package/dist/next/index.js.map +1 -0
  47. package/dist/next/logout-button.d.ts +7 -0
  48. package/dist/next/logout-button.d.ts.map +1 -0
  49. package/dist/next/logout-button.js +12 -0
  50. package/dist/next/logout-button.js.map +1 -0
  51. package/dist/next/messages.d.ts +5 -0
  52. package/dist/next/messages.d.ts.map +1 -0
  53. package/dist/next/messages.js +7 -0
  54. package/dist/next/messages.js.map +1 -0
  55. package/dist/next/pages.d.ts +18 -0
  56. package/dist/next/pages.d.ts.map +1 -0
  57. package/dist/next/pages.js +92 -0
  58. package/dist/next/pages.js.map +1 -0
  59. package/dist/next/params.d.ts +3 -0
  60. package/dist/next/params.d.ts.map +1 -0
  61. package/dist/next/params.js +4 -0
  62. package/dist/next/params.js.map +1 -0
  63. package/dist/next/route.d.ts +3 -0
  64. package/dist/next/route.d.ts.map +1 -0
  65. package/dist/next/route.js +17 -0
  66. package/dist/next/route.js.map +1 -0
  67. package/dist/next/search-params.d.ts +5 -0
  68. package/dist/next/search-params.d.ts.map +1 -0
  69. package/dist/next/search-params.js +13 -0
  70. package/dist/next/search-params.js.map +1 -0
  71. package/dist/next/session-cookie.d.ts +8 -0
  72. package/dist/next/session-cookie.d.ts.map +1 -0
  73. package/dist/next/session-cookie.js +34 -0
  74. package/dist/next/session-cookie.js.map +1 -0
  75. package/dist/options.d.ts +63 -0
  76. package/dist/options.d.ts.map +1 -0
  77. package/dist/options.js +74 -0
  78. package/dist/options.js.map +1 -0
  79. package/dist/password-reset-sender.d.ts +21 -0
  80. package/dist/password-reset-sender.d.ts.map +1 -0
  81. package/dist/password-reset-sender.js +12 -0
  82. package/dist/password-reset-sender.js.map +1 -0
  83. package/dist/proxy/index.d.ts +9 -0
  84. package/dist/proxy/index.d.ts.map +1 -0
  85. package/dist/proxy/index.js +41 -0
  86. package/dist/proxy/index.js.map +1 -0
  87. package/dist/redirect-target.d.ts +7 -0
  88. package/dist/redirect-target.d.ts.map +1 -0
  89. package/dist/redirect-target.js +25 -0
  90. package/dist/redirect-target.js.map +1 -0
  91. package/dist/roles.d.ts +5 -0
  92. package/dist/roles.d.ts.map +1 -0
  93. package/dist/roles.js +6 -0
  94. package/dist/roles.js.map +1 -0
  95. package/dist/safe-next-path.d.ts +3 -0
  96. package/dist/safe-next-path.d.ts.map +1 -0
  97. package/dist/safe-next-path.js +19 -0
  98. package/dist/safe-next-path.js.map +1 -0
  99. package/dist/schema.d.ts +302 -0
  100. package/dist/schema.d.ts.map +1 -0
  101. package/dist/schema.js +37 -0
  102. package/dist/schema.js.map +1 -0
  103. package/dist/scripts/index.d.ts +2 -0
  104. package/dist/scripts/index.d.ts.map +1 -0
  105. package/dist/scripts/index.js +3 -0
  106. package/dist/scripts/index.js.map +1 -0
  107. package/dist/scripts/role-scripts.d.ts +15 -0
  108. package/dist/scripts/role-scripts.d.ts.map +1 -0
  109. package/dist/scripts/role-scripts.js +76 -0
  110. package/dist/scripts/role-scripts.js.map +1 -0
  111. package/dist/server/change-password.d.ts +14 -0
  112. package/dist/server/change-password.d.ts.map +1 -0
  113. package/dist/server/change-password.js +47 -0
  114. package/dist/server/change-password.js.map +1 -0
  115. package/dist/server/health.d.ts +3 -0
  116. package/dist/server/health.d.ts.map +1 -0
  117. package/dist/server/health.js +15 -0
  118. package/dist/server/health.js.map +1 -0
  119. package/dist/server/index.d.ts +12 -0
  120. package/dist/server/index.d.ts.map +1 -0
  121. package/dist/server/index.js +14 -0
  122. package/dist/server/index.js.map +1 -0
  123. package/dist/server/login.d.ts +14 -0
  124. package/dist/server/login.d.ts.map +1 -0
  125. package/dist/server/login.js +49 -0
  126. package/dist/server/login.js.map +1 -0
  127. package/dist/server/options.d.ts +17 -0
  128. package/dist/server/options.d.ts.map +1 -0
  129. package/dist/server/options.js +36 -0
  130. package/dist/server/options.js.map +1 -0
  131. package/dist/server/password-reset.d.ts +54 -0
  132. package/dist/server/password-reset.d.ts.map +1 -0
  133. package/dist/server/password-reset.js +134 -0
  134. package/dist/server/password-reset.js.map +1 -0
  135. package/dist/server/password.d.ts +18 -0
  136. package/dist/server/password.d.ts.map +1 -0
  137. package/dist/server/password.js +77 -0
  138. package/dist/server/password.js.map +1 -0
  139. package/dist/server/privacy.d.ts +33 -0
  140. package/dist/server/privacy.d.ts.map +1 -0
  141. package/dist/server/privacy.js +52 -0
  142. package/dist/server/privacy.js.map +1 -0
  143. package/dist/server/rate-limits.d.ts +21 -0
  144. package/dist/server/rate-limits.d.ts.map +1 -0
  145. package/dist/server/rate-limits.js +39 -0
  146. package/dist/server/rate-limits.js.map +1 -0
  147. package/dist/server/reauthenticate.d.ts +7 -0
  148. package/dist/server/reauthenticate.d.ts.map +1 -0
  149. package/dist/server/reauthenticate.js +16 -0
  150. package/dist/server/reauthenticate.js.map +1 -0
  151. package/dist/server/register.d.ts +21 -0
  152. package/dist/server/register.d.ts.map +1 -0
  153. package/dist/server/register.js +52 -0
  154. package/dist/server/register.js.map +1 -0
  155. package/dist/server/roles.d.ts +25 -0
  156. package/dist/server/roles.d.ts.map +1 -0
  157. package/dist/server/roles.js +56 -0
  158. package/dist/server/roles.js.map +1 -0
  159. package/dist/server/session-token.d.ts +8 -0
  160. package/dist/server/session-token.d.ts.map +1 -0
  161. package/dist/server/session-token.js +18 -0
  162. package/dist/server/session-token.js.map +1 -0
  163. package/dist/server/sessions.d.ts +15 -0
  164. package/dist/server/sessions.d.ts.map +1 -0
  165. package/dist/server/sessions.js +41 -0
  166. package/dist/server/sessions.js.map +1 -0
  167. package/dist/server/switches.d.ts +9 -0
  168. package/dist/server/switches.d.ts.map +1 -0
  169. package/dist/server/switches.js +34 -0
  170. package/dist/server/switches.js.map +1 -0
  171. package/dist/server/validation.d.ts +10 -0
  172. package/dist/server/validation.d.ts.map +1 -0
  173. package/dist/server/validation.js +32 -0
  174. package/dist/server/validation.js.map +1 -0
  175. package/dist/session-cookie.d.ts +14 -0
  176. package/dist/session-cookie.d.ts.map +1 -0
  177. package/dist/session-cookie.js +31 -0
  178. package/dist/session-cookie.js.map +1 -0
  179. package/dist/ui/auth-forms.d.ts +57 -0
  180. package/dist/ui/auth-forms.d.ts.map +1 -0
  181. package/dist/ui/auth-forms.js +65 -0
  182. package/dist/ui/auth-forms.js.map +1 -0
  183. package/dist/ui/index.d.ts +2 -0
  184. package/dist/ui/index.d.ts.map +1 -0
  185. package/dist/ui/index.js +4 -0
  186. package/dist/ui/index.js.map +1 -0
  187. package/migrations/0001_create_users_and_sessions.sql +25 -0
  188. package/migrations/0002_create_user_roles.sql +10 -0
  189. package/migrations/0003_create_password_resets.sql +15 -0
  190. package/migrations/0004_index_users_created_at.sql +5 -0
  191. package/module.json +34 -0
  192. package/package.json +85 -4
  193. package/src/contract.ts +64 -0
  194. package/src/index.ts +100 -0
  195. package/src/mailing/index.ts +3 -0
  196. package/src/mailing/reset-mail.ts +73 -0
  197. package/src/messages/en.ts +91 -0
  198. package/src/messages/index.ts +15 -0
  199. package/src/messages/pl.ts +92 -0
  200. package/src/next/actions.ts +216 -0
  201. package/src/next/context.ts +14 -0
  202. package/src/next/current-user.ts +90 -0
  203. package/src/next/index.ts +24 -0
  204. package/src/next/logout-button.tsx +22 -0
  205. package/src/next/messages.ts +9 -0
  206. package/src/next/next-modules.d.ts +16 -0
  207. package/src/next/pages.tsx +179 -0
  208. package/src/next/params.ts +4 -0
  209. package/src/next/route.ts +17 -0
  210. package/src/next/search-params.ts +14 -0
  211. package/src/next/session-cookie.ts +39 -0
  212. package/src/options.ts +108 -0
  213. package/src/password-reset-sender.ts +33 -0
  214. package/src/proxy/index.ts +58 -0
  215. package/src/redirect-target.ts +24 -0
  216. package/src/roles.ts +7 -0
  217. package/src/safe-next-path.ts +15 -0
  218. package/src/schema.ts +45 -0
  219. package/src/scripts/index.ts +2 -0
  220. package/src/scripts/role-scripts.ts +98 -0
  221. package/src/server/change-password.ts +61 -0
  222. package/src/server/health.ts +16 -0
  223. package/src/server/index.ts +38 -0
  224. package/src/server/login.ts +61 -0
  225. package/src/server/options.ts +49 -0
  226. package/src/server/password-reset.ts +164 -0
  227. package/src/server/password.ts +90 -0
  228. package/src/server/privacy.ts +70 -0
  229. package/src/server/rate-limits.ts +44 -0
  230. package/src/server/reauthenticate.ts +16 -0
  231. package/src/server/register.ts +72 -0
  232. package/src/server/roles.ts +72 -0
  233. package/src/server/session-token.ts +21 -0
  234. package/src/server/sessions.ts +50 -0
  235. package/src/server/switches.ts +31 -0
  236. package/src/server/validation.ts +37 -0
  237. package/src/session-cookie.ts +47 -0
  238. package/src/ui/auth-forms.tsx +364 -0
  239. package/src/ui/index.ts +16 -0
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { formatMessage } from "@softure-ai/core";
4
+ import { Button, Checkbox, createSlotClassGetter, FormError, PasswordField, TextField } from "@softure-ai/ui";
5
+ import { useActionState } from "react";
6
+ import { INITIAL_AUTH_FORM_STATE } from "../contract.js";
7
+ import { getAuthErrorMessage } from "../messages/index.js";
8
+ const DEFAULT_CLASSES = {
9
+ root: "sft:flex sft:flex-col sft:gap-3 sft:font-sans",
10
+ form: "sft:flex sft:flex-col sft:gap-3",
11
+ footer: "sft:m-0 sft:text-sm sft:text-muted",
12
+ link: "sft:font-medium sft:text-accent",
13
+ notice: "sft:m-0 sft:text-sm sft:text-success",
14
+ };
15
+ /** The error of one field, or of the form when no field owns it. */
16
+ function useErrors(state, messages) {
17
+ const message = state.error === undefined ? undefined : getAuthErrorMessage(messages, state.error);
18
+ return {
19
+ at: (field) => (state.field === field ? message : undefined),
20
+ form: state.field === undefined ? message : undefined,
21
+ };
22
+ }
23
+ function FormShell({ formAction, isPending, submitLabel, pendingLabel, formError, footer, slot, unstyled, children, }) {
24
+ return (_jsxs("div", { className: slot("root"), children: [_jsxs("form", { action: formAction, className: slot("form"), children: [children, _jsx(FormError, { message: formError, unstyled: unstyled }), _jsx(Button, { type: "submit", variant: "primary", fullWidth: true, pending: isPending, unstyled: unstyled, children: isPending ? pendingLabel : submitLabel })] }), footer] }));
25
+ }
26
+ export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled }) {
27
+ const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
28
+ const errors = useErrors(state, messages);
29
+ const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
30
+ const footer = registerHref === undefined && forgotPasswordHref === undefined && notice === undefined ? undefined : (_jsxs(_Fragment, { children: [notice === undefined ? null : (_jsx("p", { role: "status", className: slot("notice"), children: notice })), forgotPasswordHref === undefined ? null : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: forgotPasswordHref, className: slot("link"), children: messages.login.forgotPassword }) })), registerHref === undefined ? null : (_jsxs("p", { className: slot("footer"), children: [messages.login.noAccount, " ", _jsx("a", { href: registerHref, className: slot("link"), children: messages.login.registerLink })] }))] }));
31
+ return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.login.submit, pendingLabel: messages.login.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, autoComplete: "current-password", error: errors.at("password"), unstyled: unstyled, locale: locale })] }));
32
+ }
33
+ export function RegisterForm({ action, messages, locale, next, loginHref, requireConsent, minPasswordLength, consentLabel, classNames, unstyled, }) {
34
+ const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
35
+ const errors = useErrors(state, messages);
36
+ const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
37
+ const footer = loginHref === undefined ? undefined : (_jsxs("p", { className: slot("footer"), children: [messages.register.hasAccount, " ", _jsx("a", { href: loginHref, className: slot("link"), children: messages.register.loginLink })] }));
38
+ return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.register.submit, pendingLabel: messages.register.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "password", label: messages.fields.password, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("password"), unstyled: unstyled, locale: locale }), requireConsent ? (_jsx(Checkbox, { name: "consent", label: consentLabel ?? messages.fields.consent, required: true, error: errors.at("consent"), unstyled: unstyled })) : null] }));
39
+ }
40
+ export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled }) {
41
+ const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
42
+ const errors = useErrors(state, messages);
43
+ const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
44
+ const notice = state.status === "ok" ? (_jsx("p", { role: "status", className: slot("notice"), children: messages.changePassword.success })) : undefined;
45
+ return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.changePassword.submit, pendingLabel: messages.changePassword.pending, formError: errors.form, footer: notice, slot: slot, unstyled: unstyled, children: [_jsx(PasswordField, { name: "currentPassword", label: messages.fields.currentPassword, autoComplete: "current-password", error: errors.at("currentPassword"), unstyled: unstyled, locale: locale }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
46
+ }
47
+ /** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
48
+ export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled }) {
49
+ const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
50
+ const errors = useErrors(state, messages);
51
+ const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
52
+ const backToLogin = loginHref === undefined ? undefined : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: loginHref, className: slot("link"), children: messages.forgotPassword.backToLogin }) }));
53
+ if (state.status === "ok") {
54
+ return (_jsxs("div", { className: slot("root"), children: [_jsx("p", { role: "status", className: slot("notice"), children: formatMessage(messages.forgotPassword.sent, { ttlMinutes }) }), backToLogin] }));
55
+ }
56
+ return (_jsx(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.forgotPassword.submit, pendingLabel: messages.forgotPassword.pending, formError: errors.form, footer: backToLogin, slot: slot, unstyled: unstyled, children: _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), unstyled: unstyled, locale: locale }) }));
57
+ }
58
+ /** Sets a new password from a reset link; its action goes to the login page on success. */
59
+ export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled }) {
60
+ const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
61
+ const errors = useErrors(state, messages);
62
+ const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
63
+ return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.resetPassword.submit, pendingLabel: messages.resetPassword.pending, formError: errors.form, slot: slot, unstyled: unstyled, children: [_jsx("input", { type: "hidden", name: "token", value: token }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), unstyled: unstyled, locale: locale })] }));
64
+ }
65
+ //# sourceM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,EAC1C,YAAY,EAAE,QAAQ,CAAC,aAAa,CAAC,OAAO,EAC5C,SAAS,EAAE,MAAM,CAAC,IAAI,EACtB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,aAElB,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,KAAK,GAAI,EAClD,KAAC,aAAa,IACZ,IAAI,EAAC,aAAa,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAClC,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,EACtF,YAAY,EAAC,cAAc,EAC3B,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,EAC/B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACd,IACQ,CACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { type AuthFormAction, type AuthFormSlot, ChangePasswordForm, type ChangePasswordFormProps, ForgotPasswordForm, type ForgotPasswordFormProps, LoginForm, type LoginFormProps, RegisterForm, type RegisterFormProps, ResetPasswordForm, type ResetPasswordFormProps, } from "./auth-forms.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,SAAS,EACT,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ // The auth forms, to compose into the app's own pages. They take the server actions from
2
+ // `@softure-ai/auth/next` as props: no `next/*` import here (docs/02-module-standard.md §5).
3
+ export { ChangePasswordForm, ForgotPasswordForm, LoginForm, RegisterForm, ResetPasswordForm, } from "./auth-forms.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,6FAA6F;AAC7F,OAAO,EAGL,kBAAkB,EAElB,kBAAkB,EAElB,SAAS,EAET,YAAY,EAEZ,iBAAiB,GAElB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,25 @@
1
+ -- Accounts and their database sessions.
2
+ -- Rollback: DROP TABLE auth.sessions; DROP TABLE auth.users; then
3
+ -- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 1;
4
+ CREATE TABLE users (
5
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
6
+ -- Stored trimmed and lowercased, so the unique constraint is the case-insensitive one.
7
+ email text NOT NULL CHECK (email = lower(btrim(email)) AND char_length(email) BETWEEN 3 AND 254),
8
+ password_hash text NOT NULL CHECK (password_hash LIKE 'scrypt$%'),
9
+ created_at timestamptz NOT NULL,
10
+ password_changed_at timestamptz NOT NULL,
11
+ CONSTRAINT users_email_key UNIQUE (email)
12
+ );
13
+
14
+ -- Only the sha256 of a session token is stored; the token itself lives in the cookie alone.
15
+ CREATE TABLE sessions (
16
+ token_hash text PRIMARY KEY CHECK (token_hash ~ '^[0-9a-f]{64}$'),
17
+ user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
18
+ created_at timestamptz NOT NULL,
19
+ expires_at timestamptz NOT NULL,
20
+ CHECK (expires_at > created_at)
21
+ );
22
+
23
+ -- A password change and the login cleanup delete by user; pruning deletes by age.
24
+ CREATE INDEX sessions_user_id_idx ON sessions (user_id);
25
+ CREATE INDEX sessions_expires_at_idx ON sessions (expires_at);
@@ -0,0 +1,10 @@
1
+ -- Roles granted to accounts. A role an app checks must also be declared in auth({ roles }); `admin`
2
+ -- is always declared. Admins listed in auth({ adminEmails }) are never stored here.
3
+ -- Rollback: DROP TABLE auth.user_roles; then
4
+ -- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 2;
5
+ CREATE TABLE user_roles (
6
+ user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
7
+ role text NOT NULL CHECK (role ~ '^[a-z][a-z0-9_-]{0,31}$'),
8
+ granted_at timestamptz NOT NULL,
9
+ PRIMARY KEY (user_id, role)
10
+ );
@@ -0,0 +1,15 @@
1
+ -- Pending password resets: at most one per account (a new request replaces the token), only the
2
+ -- sha256 of the token is stored, and a reset deletes its row, so a link works once.
3
+ -- Rollback: DROP TABLE auth.password_resets; then
4
+ -- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 3;
5
+ CREATE TABLE password_resets (
6
+ user_id uuid PRIMARY KEY REFERENCES users (id) ON DELETE CASCADE,
7
+ token_hash text NOT NULL CHECK (token_hash ~ '^[0-9a-f]{64}$'),
8
+ created_at timestamptz NOT NULL,
9
+ expires_at timestamptz NOT NULL,
10
+ CHECK (expires_at > created_at),
11
+ CONSTRAINT password_resets_token_hash_key UNIQUE (token_hash)
12
+ );
13
+
14
+ -- Pruning deletes by age.
15
+ CREATE INDEX password_resets_expires_at_idx ON password_resets (expires_at);
@@ -0,0 +1,5 @@
1
+ -- Accounts by creation time: billing finds the accounts whose derived trial is in a reminder
2
+ -- window with a range on created_at, without scanning every account.
3
+ -- Rollback: DROP INDEX auth.users_created_at_idx; then
4
+ -- DELETE FROM softure.migrations WHERE module = 'auth' AND version = 4;
5
+ CREATE INDEX users_created_at_idx ON users (created_at);
package/module.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": "auth",
3
+ "version": "0.1.5",
4
+ "dependsOn": { "security": "^0.1.0" },
5
+ "dbSchema": "auth",
6
+ "tables": ["users", "sessions", "user_roles", "password_resets"],
7
+ "env": [
8
+ {
9
+ "name": "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED",
10
+ "required": false,
11
+ "description": "Overrides the auth.registration_closed switch: true or 1 closes registration, false or 0 opens it."
12
+ }
13
+ ],
14
+ "switches": ["auth.registration_closed"],
15
+ "routes": {
16
+ "login": "/login",
17
+ "register": "/register",
18
+ "changePassword": "/account/password",
19
+ "forgotPassword": "/forgot-password",
20
+ "resetPassword": "/reset-password",
21
+ "afterLogin": "/",
22
+ "afterLogout": "/login"
23
+ },
24
+ "mount": [
25
+ { "kind": "page", "path": "app/login/page.tsx", "export": "LoginPage" },
26
+ { "kind": "page", "path": "app/register/page.tsx", "export": "RegisterPage" },
27
+ { "kind": "page", "path": "app/account/password/page.tsx", "export": "ChangePasswordPage" },
28
+ { "kind": "page", "path": "app/forgot-password/page.tsx", "export": "ForgotPasswordPage" },
29
+ { "kind": "page", "path": "app/reset-password/page.tsx", "export": "ResetPasswordPage" },
30
+ { "kind": "route-handler", "path": "app/api/auth/session/route.ts", "export": "getSessionRoute" },
31
+ { "kind": "middleware", "path": "proxy.ts", "export": "createAuthGuard" }
32
+ ],
33
+ "privacy": { "exports": true, "deletes": true }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,87 @@
1
1
  {
2
2
  "name": "@softure-ai/auth",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.5",
4
+ "description": "SOFTURE AI auth module: users, scrypt passwords, database sessions, register with consent, login, logout, password change, roles, a proxy route guard, pages and forms for Next.js, and a password reset sender over @softure-ai/mailing.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "engines": {
9
+ "node": ">=22"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/SOFTURE/AI.git",
14
+ "directory": "modules/auth"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "!src/**/*.test.ts",
20
+ "!src/**/*.test.tsx",
21
+ "migrations",
22
+ "module.json"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "provenance": true
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "@softure-ai/source": "./src/index.ts",
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./server": {
35
+ "@softure-ai/source": "./src/server/index.ts",
36
+ "types": "./dist/server/index.d.ts",
37
+ "default": "./dist/server/index.js"
38
+ },
39
+ "./next": {
40
+ "@softure-ai/source": "./src/next/index.ts",
41
+ "types": "./dist/next/index.d.ts",
42
+ "default": "./dist/next/index.js"
43
+ },
44
+ "./mailing": {
45
+ "@softure-ai/source": "./src/mailing/index.ts",
46
+ "types": "./dist/mailing/index.d.ts",
47
+ "default": "./dist/mailing/index.js"
48
+ },
49
+ "./proxy": {
50
+ "@softure-ai/source": "./src/proxy/index.ts",
51
+ "types": "./dist/proxy/index.d.ts",
52
+ "default": "./dist/proxy/index.js"
53
+ },
54
+ "./scripts": {
55
+ "@softure-ai/source": "./src/scripts/index.ts",
56
+ "types": "./dist/scripts/index.d.ts",
57
+ "default": "./dist/scripts/index.js"
58
+ },
59
+ "./ui": {
60
+ "@softure-ai/source": "./src/ui/index.ts",
61
+ "types": "./dist/ui/index.d.ts",
62
+ "default": "./dist/ui/index.js"
63
+ }
64
+ },
65
+ "scripts": {
66
+ "build": "tsc -p tsconfig.build.json"
67
+ },
68
+ "dependencies": {
69
+ "@softure-ai/core": "^0.1.0",
70
+ "@softure-ai/db": "^0.1.0",
71
+ "@softure-ai/ops": "^0.1.0",
72
+ "@softure-ai/security": "^0.1.0",
73
+ "@softure-ai/ui": "^0.1.0",
74
+ "zod": "^4.6.5"
75
+ },
76
+ "peerDependencies": {
77
+ "@softure-ai/mailing": "^0.1.0",
78
+ "drizzle-orm": "^0.45.2",
79
+ "next": "^16.0.0",
80
+ "react": "^19.0.0"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "@softure-ai/mailing": {
84
+ "optional": true
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,64 @@
1
+ // Result types and error codes of the auth module. No user-facing copy here: the UI translates
2
+ // codes through `messages` (docs/02-module-standard.md §6).
3
+ import type { CoreErrorCode } from "@softure-ai/core";
4
+ import type { SecurityErrorCode } from "@softure-ai/security";
5
+
6
+ export type AuthErrorCode =
7
+ | "auth.invalid_credentials"
8
+ | "auth.email_invalid"
9
+ | "auth.email_taken"
10
+ | "auth.password_too_short"
11
+ | "auth.password_too_long"
12
+ | "auth.consent_required"
13
+ | "auth.registration_closed"
14
+ | "auth.current_password_invalid"
15
+ | "auth.unauthenticated"
16
+ | "auth.forbidden"
17
+ | "auth.reset_token_invalid"
18
+ | "auth.password_reset_unavailable";
19
+
20
+ /** Every code an auth form can show: its own, the rate limiter's and the generic ones. */
21
+ export type AuthFormErrorCode = AuthErrorCode | Extract<SecurityErrorCode, "security.rate_limited" | "security.client_unidentified"> | CoreErrorCode;
22
+
23
+ /** A signed-up account, as the app sees it. The password hash never leaves the module. */
24
+ export interface AuthUser {
25
+ readonly id: string;
26
+ readonly email: string;
27
+ readonly createdAt: Date;
28
+ }
29
+
30
+ /** A session just opened: the token goes into the cookie and is never stored. */
31
+ export interface NewSession {
32
+ readonly token: string;
33
+ readonly expiresAt: Date;
34
+ }
35
+
36
+ /** A successful register or login. */
37
+ export interface SignedIn {
38
+ readonly user: AuthUser;
39
+ readonly session: NewSession;
40
+ }
41
+
42
+ /** What `onRegistered` receives. `consent` is null when the app turned `requireConsent` off. */
43
+ export interface RegisteredEvent {
44
+ readonly user: AuthUser;
45
+ readonly consent: { readonly acceptedAt: Date } | null;
46
+ }
47
+
48
+ /** The fields of the auth forms that can carry their own error. */
49
+ export type AuthFormField = "email" | "password" | "currentPassword" | "newPassword" | "consent";
50
+
51
+ /**
52
+ * What an auth server action returns to its form (`useActionState`). A successful login or
53
+ * register redirects instead of returning; a password change returns `ok`.
54
+ */
55
+ export interface AuthFormState {
56
+ readonly status: "idle" | "ok" | "error";
57
+ /** The error to show; when `field` is set it is shown at that field. */
58
+ readonly error?: AuthFormErrorCode;
59
+ readonly field?: AuthFormField;
60
+ /** The submitted email, so a rejected form keeps it (passwords are never sent back). */
61
+ readonly email?: string;
62
+ }
63
+
64
+ export const INITIAL_AUTH_FORM_STATE: AuthFormState = { status: "idle" };
package/src/index.ts ADDED
@@ -0,0 +1,100 @@
1
+ // Public API of @softure-ai/auth: the module factory for softure.config.ts, its types, messages and
2
+ // tables, and the development reset sender. Database work is in `@softure-ai/auth/server`, the Next.js adapter in `/next`, the route
3
+ // guard in `/proxy`, the forms in `/ui` and the role scripts in `/scripts`.
4
+ import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
5
+ import { authMessages } from "./messages/index.js";
6
+ import { authOptionsSchema } from "./options.js";
7
+ import { checkAuthTables } from "./server/health.js";
8
+ import { authPrivacyContributor } from "./server/privacy.js";
9
+
10
+ export const MODULE_ID = "auth";
11
+
12
+ /** Name of the runtime switch that closes registration. */
13
+ export const REGISTRATION_CLOSED_SWITCH = "auth.registration_closed";
14
+
15
+ /**
16
+ * The env override of that switch: `true`/`1` or `false`/`0` while auth reads it itself. When the app
17
+ * defines the switch in `@softure-ai/feature-switches`, that module reads the same variable.
18
+ */
19
+ export const REGISTRATION_CLOSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED";
20
+
21
+ /**
22
+ * Rate limit buckets auth consumes, with defaults to spread into `security({ buckets })`:
23
+ * `register` and `login` per client address, `login-account` per email, `change-password` per user,
24
+ * `password-reset` (link requests) and `password-reset-confirm` (new passwords) per client address,
25
+ * and `password-reset-account` per email, which bounds the mails one address can receive.
26
+ */
27
+ export const AUTH_RATE_LIMIT_BUCKETS = {
28
+ register: { limit: 5, windowMinutes: 15 },
29
+ login: { limit: 50, windowMinutes: 15 },
30
+ "login-account": { limit: 10, windowMinutes: 15 },
31
+ "change-password": { limit: 10, windowMinutes: 15 },
32
+ "password-reset": { limit: 10, windowMinutes: 15 },
33
+ "password-reset-account": { limit: 3, windowMinutes: 15 },
34
+ "password-reset-confirm": { limit: 10, windowMinutes: 15 },
35
+ } as const;
36
+
37
+ /**
38
+ * Enables accounts in `softure.config.ts` (next to `security({ ... })`):
39
+ * `auth({ routes: { afterLogin: "/dashboard" }, password: { minLength: 12 } })`.
40
+ */
41
+ export const auth = defineModule({
42
+ manifest: {
43
+ id: MODULE_ID,
44
+ version: "0.1.5",
45
+ dependsOn: { security: "^0.1.0" },
46
+ dbSchema: "auth",
47
+ tables: ["users", "sessions", "user_roles", "password_resets"],
48
+ env: [
49
+ {
50
+ name: REGISTRATION_CLOSED_ENV,
51
+ required: false,
52
+ description: "Overrides the auth.registration_closed switch: true or 1 closes registration, false or 0 opens it.",
53
+ },
54
+ ],
55
+ switches: [REGISTRATION_CLOSED_SWITCH],
56
+ routes: {
57
+ login: "/login",
58
+ register: "/register",
59
+ changePassword: "/account/password",
60
+ forgotPassword: "/forgot-password",
61
+ resetPassword: "/reset-password",
62
+ afterLogin: "/",
63
+ afterLogout: "/login",
64
+ },
65
+ mount: [
66
+ { kind: "page", path: "app/login/page.tsx", export: "LoginPage" },
67
+ { kind: "page", path: "app/register/page.tsx", export: "RegisterPage" },
68
+ { kind: "page", path: "app/account/password/page.tsx", export: "ChangePasswordPage" },
69
+ { kind: "page", path: "app/forgot-password/page.tsx", export: "ForgotPasswordPage" },
70
+ { kind: "page", path: "app/reset-password/page.tsx", export: "ResetPasswordPage" },
71
+ { kind: "route-handler", path: "app/api/auth/session/route.ts", export: "getSessionRoute" },
72
+ { kind: "middleware", path: "proxy.ts", export: "createAuthGuard" },
73
+ ],
74
+ privacy: { exports: true, deletes: true },
75
+ },
76
+ messages: authMessages,
77
+ options: authOptionsSchema,
78
+ migrations: { dir: resolveMigrationsDir(import.meta.url, "../migrations/") },
79
+ privacy: authPrivacyContributor,
80
+ health: checkAuthTables,
81
+ });
82
+
83
+ export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
84
+ export type {
85
+ AuthErrorCode,
86
+ AuthFormErrorCode,
87
+ AuthFormField,
88
+ AuthFormState,
89
+ AuthUser,
90
+ NewSession,
91
+ RegisteredEvent,
92
+ SignedIn,
93
+ } from "./contract.js";
94
+ export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
95
+ export type { AuthOptions, AuthOptionsInput, OnRegisteredHook, RewriteRedirect, RewriteRedirectContext, ScryptParams } from "./options.js";
96
+ export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetSender } from "./password-reset-sender.js";
97
+ export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
98
+ export { toSafeNextPath } from "./safe-next-path.js";
99
+ export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
100
+ export { passwordResets, sessions, userRoles, users } from "./schema.js";
@@ -0,0 +1,3 @@
1
+ // The mailing adapter of @softure-ai/auth: password reset mails through `@softure-ai/mailing`
2
+ // (an optional peer dependency; only apps that import this entry need it).
3
+ export { mailingResetSender, renderPasswordResetMail, type PasswordResetMail, type PasswordResetMailInput } from "./reset-mail.js";
@@ -0,0 +1,73 @@
1
+ // The password reset mail: rendered from auth's dictionaries in the app's locale and sent through
2
+ // `@softure-ai/mailing`. A transactional mail: no unsubscribe link, never suppressed. The link is
3
+ // placed by the code, never by a translatable string, so a copy override cannot drop it.
4
+ import { formatMessage, selectPlural, type Locale, type SoftureConfig } from "@softure-ai/core";
5
+ import { getSoftureConfig } from "@softure-ai/core/next";
6
+ import type { OutgoingMail } from "@softure-ai/mailing";
7
+ import { sendMail } from "@softure-ai/mailing/server";
8
+ import type { AuthMessages } from "../messages/index.js";
9
+ import type { PasswordResetSender } from "../password-reset-sender.js";
10
+ import { getAuthModule, getAuthOptions } from "../server/options.js";
11
+
12
+ export interface PasswordResetMailInput {
13
+ /** The reset link auth hands to the sender. */
14
+ readonly link: string;
15
+ /** How long the link works (`passwordReset.ttlMinutes`). */
16
+ readonly ttlMinutes: number;
17
+ }
18
+
19
+ /** The subject and bodies of a reset mail, without the recipient. */
20
+ export type PasswordResetMail = Pick<OutgoingMail, "subject" | "text"> & { readonly html: string };
21
+
22
+ const HTML_ESCAPES: Readonly<Record<string, string>> = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
23
+
24
+ function escapeHtml(value: string): string {
25
+ return value.replace(/[&<>"']/g, (character) => HTML_ESCAPES[character] ?? character);
26
+ }
27
+
28
+ /**
29
+ * Renders the reset mail from `messages` (one locale's dictionary, overrides applied): a plain-text
30
+ * body with the bare link and an HTML body with the same paragraphs and the link as an anchor.
31
+ */
32
+ export function renderPasswordResetMail(messages: AuthMessages, locale: Locale, input: PasswordResetMailInput): PasswordResetMail {
33
+ const copy = messages.resetMail;
34
+ const duration = formatMessage(selectPlural(locale, input.ttlMinutes, copy.minutes), { count: input.ttlMinutes });
35
+ const expiry = formatMessage(copy.expiry, { duration });
36
+
37
+ const text = [copy.greeting, copy.intro, input.link, expiry, copy.ignore].join("\n\n");
38
+ const paragraphs = [
39
+ escapeHtml(copy.greeting),
40
+ escapeHtml(copy.intro),
41
+ `<a href="${escapeHtml(input.link)}">${escapeHtml(copy.action)}</a>`,
42
+ escapeHtml(expiry),
43
+ escapeHtml(copy.ignore),
44
+ ];
45
+ const html = paragraphs.map((paragraph) => `<p>${paragraph}</p>`).join("\n");
46
+ return { subject: copy.subject, text, html };
47
+ }
48
+
49
+ /** The app's auth dictionary for `locale`, with its overrides applied. */
50
+ function getMessages(config: SoftureConfig, locale: Locale): AuthMessages {
51
+ // The module factory merged the dictionaries; their shape is the module's own.
52
+ return getAuthModule(config).messages[locale] as AuthMessages;
53
+ }
54
+
55
+ /**
56
+ * A `passwordReset.send` that mails the link through `@softure-ai/mailing`:
57
+ * `auth({ passwordReset: { send: mailingResetSender() } })` next to `mailing({ ... })`. It reads the
58
+ * registered config (`registerSoftureConfig`) when it runs. A failed send throws an error naming
59
+ * the `mailing.*` code (never the address or the link), which auth logs.
60
+ */
61
+ export function mailingResetSender(): PasswordResetSender {
62
+ return async (link, user, details) => {
63
+ const config = getSoftureConfig();
64
+ const mail = renderPasswordResetMail(getMessages(config, details.locale), details.locale, {
65
+ link,
66
+ ttlMinutes: getAuthOptions(config).passwordReset.ttlMinutes,
67
+ });
68
+ const result = await sendMail({ config }, { to: user.email, ...mail });
69
+ if (!result.ok) {
70
+ throw new Error(`@softure-ai/auth: the password reset mail was not sent (${result.error})`);
71
+ }
72
+ };
73
+ }
@@ -0,0 +1,91 @@
1
+ export const en = {
2
+ fields: {
3
+ email: "Email",
4
+ password: "Password",
5
+ currentPassword: "Current password",
6
+ newPassword: "New password",
7
+ newPasswordHint: "At least {minLength} characters.",
8
+ consent: "I accept the terms of service and the privacy policy.",
9
+ },
10
+ login: {
11
+ title: "Log in",
12
+ lead: "Welcome back.",
13
+ submit: "Log in",
14
+ pending: "Logging in…",
15
+ noAccount: "No account yet?",
16
+ registerLink: "Create one",
17
+ forgotPassword: "Forgot your password?",
18
+ },
19
+ register: {
20
+ title: "Create an account",
21
+ lead: "It takes a minute.",
22
+ submit: "Create account",
23
+ pending: "Creating…",
24
+ hasAccount: "Already have an account?",
25
+ loginLink: "Log in",
26
+ closedTitle: "Registration is closed",
27
+ closedBody: "New accounts cannot be created right now. Try again later.",
28
+ },
29
+ changePassword: {
30
+ title: "Change password",
31
+ lead: "Every other device you are logged in on will be logged out.",
32
+ submit: "Change password",
33
+ pending: "Saving…",
34
+ success: "Your password has been changed.",
35
+ },
36
+ forgotPassword: {
37
+ title: "Reset your password",
38
+ lead: "Enter the email of your account and we will send you a link to set a new password.",
39
+ submit: "Send the link",
40
+ pending: "Sending…",
41
+ sent: "If an account uses this email, a link to reset its password is on its way. It works for {ttlMinutes} minutes.",
42
+ backToLogin: "Back to login",
43
+ },
44
+ resetPassword: {
45
+ title: "Set a new password",
46
+ lead: "You will be logged out on every device.",
47
+ submit: "Set password",
48
+ pending: "Saving…",
49
+ success: "Your password has been changed. Log in with the new one.",
50
+ invalidTitle: "This link does not work",
51
+ invalidBody: "The link has expired or has already been used. Ask for a new one.",
52
+ requestNew: "Get a new link",
53
+ },
54
+ resetMail: {
55
+ subject: "Reset your password",
56
+ greeting: "Hello,",
57
+ intro: "We got a request to reset the password of your account. Open this link to set a new one:",
58
+ action: "Set a new password",
59
+ expiry: "The link works for {duration} and only once.",
60
+ /** `{count}` minutes, by the locale's plural rules (Intl.PluralRules categories). */
61
+ minutes: { one: "{count} minute", few: "{count} minutes", many: "{count} minutes", other: "{count} minutes" },
62
+ ignore: "If you did not ask for this, ignore this mail: your password stays as it is.",
63
+ },
64
+ logout: {
65
+ submit: "Log out",
66
+ },
67
+ errors: {
68
+ auth: {
69
+ invalid_credentials: "The email or password is incorrect.",
70
+ email_invalid: "Enter a valid email address.",
71
+ email_taken: "An account with this email already exists.",
72
+ password_too_short: "The password is too short.",
73
+ password_too_long: "The password is too long.",
74
+ consent_required: "You need to accept the terms to create an account.",
75
+ registration_closed: "Registration is closed.",
76
+ current_password_invalid: "The current password is incorrect.",
77
+ unauthenticated: "Your session has ended. Log in again.",
78
+ forbidden: "You do not have access to this.",
79
+ reset_token_invalid: "This link has expired or has already been used. Ask for a new one.",
80
+ password_reset_unavailable: "Password reset is not available.",
81
+ },
82
+ security: {
83
+ rate_limited: "Too many attempts. Wait a few minutes and try again.",
84
+ client_unidentified: "We could not verify where this request came from. Try again later.",
85
+ },
86
+ core: {
87
+ database_failed: "Something went wrong on our side. Try again in a moment.",
88
+ unexpected: "Something went wrong on our side. Try again in a moment.",
89
+ },
90
+ },
91
+ };