@softure-ai/auth 0.1.5 → 0.1.8
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 +23 -0
- package/README.md +172 -24
- package/dist/contract.d.ts +3 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts +1 -0
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +1 -0
- package/dist/messages/en.js.map +1 -1
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/pl.d.ts.map +1 -1
- package/dist/messages/pl.js +1 -0
- package/dist/messages/pl.js.map +1 -1
- package/dist/next/actions.d.ts +9 -2
- package/dist/next/actions.d.ts.map +1 -1
- package/dist/next/actions.js +51 -18
- package/dist/next/actions.js.map +1 -1
- package/dist/next/context.js +2 -2
- package/dist/next/context.js.map +1 -1
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/logout-button.d.ts +3 -1
- package/dist/next/logout-button.d.ts.map +1 -1
- package/dist/next/logout-button.js +4 -4
- package/dist/next/logout-button.js.map +1 -1
- package/dist/next/pages.d.ts +13 -0
- package/dist/next/pages.d.ts.map +1 -1
- package/dist/next/pages.js +28 -2
- package/dist/next/pages.js.map +1 -1
- package/dist/next/session-cookie.d.ts +3 -0
- package/dist/next/session-cookie.d.ts.map +1 -1
- package/dist/next/session-cookie.js +39 -2
- package/dist/next/session-cookie.js.map +1 -1
- package/dist/options.d.ts +10 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +44 -3
- package/dist/options.js.map +1 -1
- package/dist/proxy/index.d.ts +11 -0
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +60 -9
- package/dist/proxy/index.js.map +1 -1
- package/dist/safe-next-path.d.ts +3 -1
- package/dist/safe-next-path.d.ts.map +1 -1
- package/dist/safe-next-path.js +9 -3
- package/dist/safe-next-path.js.map +1 -1
- package/dist/scripts/index.d.ts +1 -0
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +3 -1
- package/dist/scripts/index.js.map +1 -1
- package/dist/scripts/temporary-password.d.ts +12 -0
- package/dist/scripts/temporary-password.d.ts.map +1 -0
- package/dist/scripts/temporary-password.js +47 -0
- package/dist/scripts/temporary-password.js.map +1 -0
- package/dist/server/change-password.d.ts +1 -1
- package/dist/server/change-password.d.ts.map +1 -1
- package/dist/server/change-password.js +4 -1
- package/dist/server/change-password.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/login.js +5 -4
- package/dist/server/login.js.map +1 -1
- package/dist/server/options.d.ts +2 -0
- package/dist/server/options.d.ts.map +1 -1
- package/dist/server/options.js +14 -0
- package/dist/server/options.js.map +1 -1
- package/dist/server/password.d.ts +10 -3
- package/dist/server/password.d.ts.map +1 -1
- package/dist/server/password.js +24 -8
- package/dist/server/password.js.map +1 -1
- package/dist/server/rate-limits.d.ts +3 -2
- package/dist/server/rate-limits.d.ts.map +1 -1
- package/dist/server/rate-limits.js +9 -3
- package/dist/server/rate-limits.js.map +1 -1
- package/dist/server/register.d.ts +2 -0
- package/dist/server/register.d.ts.map +1 -1
- package/dist/server/register.js +13 -1
- package/dist/server/register.js.map +1 -1
- package/dist/server/session-token.d.ts +6 -2
- package/dist/server/session-token.d.ts.map +1 -1
- package/dist/server/session-token.js +7 -3
- package/dist/server/session-token.js.map +1 -1
- package/dist/server/sessions.d.ts +9 -0
- package/dist/server/sessions.d.ts.map +1 -1
- package/dist/server/sessions.js +13 -4
- package/dist/server/sessions.js.map +1 -1
- package/dist/testing/account.d.ts +17 -0
- package/dist/testing/account.d.ts.map +1 -0
- package/dist/testing/account.js +31 -0
- package/dist/testing/account.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/ui/auth-forms.d.ts +14 -7
- package/dist/ui/auth-forms.d.ts.map +1 -1
- package/dist/ui/auth-forms.js +14 -12
- package/dist/ui/auth-forms.js.map +1 -1
- package/module.json +2 -2
- package/package.json +15 -3
- package/src/contract.ts +3 -0
- package/src/index.ts +2 -2
- package/src/messages/en.ts +1 -0
- package/src/messages/pl.ts +1 -0
- package/src/next/actions.ts +58 -16
- package/src/next/context.ts +2 -2
- package/src/next/index.ts +11 -1
- package/src/next/logout-button.tsx +5 -2
- package/src/next/pages.tsx +44 -0
- package/src/next/session-cookie.ts +42 -2
- package/src/options.ts +49 -3
- package/src/proxy/index.ts +78 -10
- package/src/safe-next-path.ts +9 -3
- package/src/scripts/index.ts +7 -1
- package/src/scripts/temporary-password.ts +62 -0
- package/src/server/change-password.ts +4 -1
- package/src/server/index.ts +10 -2
- package/src/server/login.ts +5 -5
- package/src/server/options.ts +15 -0
- package/src/server/password.ts +26 -8
- package/src/server/rate-limits.ts +10 -3
- package/src/server/register.ts +16 -1
- package/src/server/session-token.ts +7 -3
- package/src/server/sessions.ts +19 -4
- package/src/testing/account.ts +43 -0
- package/src/testing/index.ts +3 -0
- package/src/ui/auth-forms.tsx +26 -7
package/src/ui/auth-forms.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { formatMessage, type Locale } from "@softure-ai/core";
|
|
4
|
-
import { Button, Checkbox, type ClassNames, createSlotClassGetter, FormError, PasswordField, TextField } from "@softure-ai/ui";
|
|
4
|
+
import { Button, type ButtonVariant, Checkbox, type ClassNames, createSlotClassGetter, FormError, PasswordField, TextField } from "@softure-ai/ui";
|
|
5
5
|
import { type ReactNode, useActionState } from "react";
|
|
6
6
|
import { type AuthFormField, type AuthFormState, INITIAL_AUTH_FORM_STATE } from "../contract.js";
|
|
7
7
|
import { type AuthMessages, getAuthErrorMessage } from "../messages/index.js";
|
|
@@ -12,7 +12,7 @@ import { type AuthMessages, getAuthErrorMessage } from "../messages/index.js";
|
|
|
12
12
|
|
|
13
13
|
export type AuthFormAction = (previous: AuthFormState, formData: FormData) => Promise<AuthFormState>;
|
|
14
14
|
|
|
15
|
-
export type AuthFormSlot = "root" | "form" | "footer" | "link" | "notice";
|
|
15
|
+
export type AuthFormSlot = "root" | "form" | "footer" | "link" | "notice" | "submit";
|
|
16
16
|
|
|
17
17
|
interface AuthFormBaseProps {
|
|
18
18
|
readonly action: AuthFormAction;
|
|
@@ -21,6 +21,8 @@ interface AuthFormBaseProps {
|
|
|
21
21
|
readonly locale?: Locale;
|
|
22
22
|
readonly classNames?: ClassNames<AuthFormSlot>;
|
|
23
23
|
readonly unstyled?: boolean;
|
|
24
|
+
/** The submit button's look; `primary` by default. Its class goes in `classNames.submit`. */
|
|
25
|
+
readonly submitVariant?: ButtonVariant;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const DEFAULT_CLASSES: Readonly<Record<AuthFormSlot, string>> = {
|
|
@@ -29,6 +31,8 @@ const DEFAULT_CLASSES: Readonly<Record<AuthFormSlot, string>> = {
|
|
|
29
31
|
footer: "sft:m-0 sft:text-sm sft:text-muted",
|
|
30
32
|
link: "sft:font-medium sft:text-accent",
|
|
31
33
|
notice: "sft:m-0 sft:text-sm sft:text-success",
|
|
34
|
+
// The button styles itself; the slot only carries the app's class.
|
|
35
|
+
submit: "",
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
/** The error of one field, or of the form when no field owns it. */
|
|
@@ -49,6 +53,7 @@ function FormShell({
|
|
|
49
53
|
footer,
|
|
50
54
|
slot,
|
|
51
55
|
unstyled,
|
|
56
|
+
submitVariant = "primary",
|
|
52
57
|
children,
|
|
53
58
|
}: {
|
|
54
59
|
formAction: (formData: FormData) => void;
|
|
@@ -59,6 +64,7 @@ function FormShell({
|
|
|
59
64
|
footer?: ReactNode;
|
|
60
65
|
slot: (part: AuthFormSlot) => string | undefined;
|
|
61
66
|
unstyled: boolean | undefined;
|
|
67
|
+
submitVariant: ButtonVariant | undefined;
|
|
62
68
|
children: ReactNode;
|
|
63
69
|
}) {
|
|
64
70
|
return (
|
|
@@ -66,7 +72,7 @@ function FormShell({
|
|
|
66
72
|
<form action={formAction} className={slot("form")}>
|
|
67
73
|
{children}
|
|
68
74
|
<FormError message={formError} unstyled={unstyled} />
|
|
69
|
-
<Button type="submit" variant=
|
|
75
|
+
<Button type="submit" variant={submitVariant} fullWidth pending={isPending} classNames={{ root: slot("submit") }} unstyled={unstyled}>
|
|
70
76
|
{isPending ? pendingLabel : submitLabel}
|
|
71
77
|
</Button>
|
|
72
78
|
</form>
|
|
@@ -86,7 +92,7 @@ export interface LoginFormProps extends AuthFormBaseProps {
|
|
|
86
92
|
readonly notice?: string;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled }: LoginFormProps) {
|
|
95
|
+
export function LoginForm({ action, messages, locale, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant }: LoginFormProps) {
|
|
90
96
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
91
97
|
const errors = useErrors(state, messages);
|
|
92
98
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
@@ -125,6 +131,7 @@ export function LoginForm({ action, messages, locale, next, registerHref, forgot
|
|
|
125
131
|
footer={footer}
|
|
126
132
|
slot={slot}
|
|
127
133
|
unstyled={unstyled}
|
|
134
|
+
submitVariant={submitVariant}
|
|
128
135
|
>
|
|
129
136
|
{next === undefined ? null : <input type="hidden" name="next" value={next} />}
|
|
130
137
|
<TextField
|
|
@@ -159,6 +166,11 @@ export interface RegisterFormProps extends AuthFormBaseProps {
|
|
|
159
166
|
readonly minPasswordLength: number;
|
|
160
167
|
/** The consent statement; may contain links to the terms. Defaults to `messages.fields.consent`. */
|
|
161
168
|
readonly consentLabel?: ReactNode;
|
|
169
|
+
/**
|
|
170
|
+
* The app's own inputs, before the consent checkbox. Their values reach `onRegistered` as
|
|
171
|
+
* `event.fields` when their names are declared in `auth({ registrationFields })`.
|
|
172
|
+
*/
|
|
173
|
+
readonly extraFields?: ReactNode;
|
|
162
174
|
}
|
|
163
175
|
|
|
164
176
|
export function RegisterForm({
|
|
@@ -170,8 +182,10 @@ export function RegisterForm({
|
|
|
170
182
|
requireConsent,
|
|
171
183
|
minPasswordLength,
|
|
172
184
|
consentLabel,
|
|
185
|
+
extraFields,
|
|
173
186
|
classNames,
|
|
174
187
|
unstyled,
|
|
188
|
+
submitVariant,
|
|
175
189
|
}: RegisterFormProps) {
|
|
176
190
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
177
191
|
const errors = useErrors(state, messages);
|
|
@@ -195,6 +209,7 @@ export function RegisterForm({
|
|
|
195
209
|
footer={footer}
|
|
196
210
|
slot={slot}
|
|
197
211
|
unstyled={unstyled}
|
|
212
|
+
submitVariant={submitVariant}
|
|
198
213
|
>
|
|
199
214
|
{next === undefined ? null : <input type="hidden" name="next" value={next} />}
|
|
200
215
|
<TextField
|
|
@@ -218,6 +233,7 @@ export function RegisterForm({
|
|
|
218
233
|
unstyled={unstyled}
|
|
219
234
|
locale={locale}
|
|
220
235
|
/>
|
|
236
|
+
{extraFields}
|
|
221
237
|
{requireConsent ? (
|
|
222
238
|
<Checkbox name="consent" label={consentLabel ?? messages.fields.consent} required error={errors.at("consent")} unstyled={unstyled} />
|
|
223
239
|
) : null}
|
|
@@ -229,7 +245,7 @@ export interface ChangePasswordFormProps extends AuthFormBaseProps {
|
|
|
229
245
|
readonly minPasswordLength: number;
|
|
230
246
|
}
|
|
231
247
|
|
|
232
|
-
export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled }: ChangePasswordFormProps) {
|
|
248
|
+
export function ChangePasswordForm({ action, messages, locale, minPasswordLength, classNames, unstyled, submitVariant }: ChangePasswordFormProps) {
|
|
233
249
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
234
250
|
const errors = useErrors(state, messages);
|
|
235
251
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
@@ -249,6 +265,7 @@ export function ChangePasswordForm({ action, messages, locale, minPasswordLength
|
|
|
249
265
|
footer={notice}
|
|
250
266
|
slot={slot}
|
|
251
267
|
unstyled={unstyled}
|
|
268
|
+
submitVariant={submitVariant}
|
|
252
269
|
>
|
|
253
270
|
<PasswordField
|
|
254
271
|
name="currentPassword"
|
|
@@ -279,7 +296,7 @@ export interface ForgotPasswordFormProps extends AuthFormBaseProps {
|
|
|
279
296
|
}
|
|
280
297
|
|
|
281
298
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
282
|
-
export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled }: ForgotPasswordFormProps) {
|
|
299
|
+
export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, loginHref, classNames, unstyled, submitVariant }: ForgotPasswordFormProps) {
|
|
283
300
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
284
301
|
const errors = useErrors(state, messages);
|
|
285
302
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
@@ -311,6 +328,7 @@ export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, login
|
|
|
311
328
|
footer={backToLogin}
|
|
312
329
|
slot={slot}
|
|
313
330
|
unstyled={unstyled}
|
|
331
|
+
submitVariant={submitVariant}
|
|
314
332
|
>
|
|
315
333
|
<TextField
|
|
316
334
|
name="email"
|
|
@@ -334,7 +352,7 @@ export interface ResetPasswordFormProps extends AuthFormBaseProps {
|
|
|
334
352
|
}
|
|
335
353
|
|
|
336
354
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
337
|
-
export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled }: ResetPasswordFormProps) {
|
|
355
|
+
export function ResetPasswordForm({ action, messages, locale, token, minPasswordLength, classNames, unstyled, submitVariant }: ResetPasswordFormProps) {
|
|
338
356
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
339
357
|
const errors = useErrors(state, messages);
|
|
340
358
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
@@ -347,6 +365,7 @@ export function ResetPasswordForm({ action, messages, locale, token, minPassword
|
|
|
347
365
|
formError={errors.form}
|
|
348
366
|
slot={slot}
|
|
349
367
|
unstyled={unstyled}
|
|
368
|
+
submitVariant={submitVariant}
|
|
350
369
|
>
|
|
351
370
|
<input type="hidden" name="token" value={token} />
|
|
352
371
|
<PasswordField
|