@adonis-agora/authkit-react 0.17.0 → 0.18.0
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/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/src/components/interaction_form.d.ts +3 -3
- package/build/src/components/interaction_form.js +18 -3
- package/build/src/components/magic_link_button.d.ts +3 -1
- package/build/src/components/magic_link_button.js +6 -4
- package/build/src/interaction/urls.d.ts +3 -1
- package/build/src/interaction/urls.js +2 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type { UsePasskeyRegistrationOptions, UsePasskeyRegistrationResult, } fro
|
|
|
44
44
|
export { usePasswordStrength, heuristicScorer, } from './src/hooks/use_password_strength.js';
|
|
45
45
|
export type { PasswordStrengthScore, PasswordStrengthResult, PasswordScorer, UsePasswordStrengthOptions, } from './src/hooks/use_password_strength.js';
|
|
46
46
|
export { deriveInitials, currentUrl, buttonClass } from './src/utils.js';
|
|
47
|
-
export { interactionUrls, oauthRedirectUrl } from './src/interaction/urls.js';
|
|
47
|
+
export { interactionUrls, oauthRedirectUrl, OTP_CODE_FIELD } from './src/interaction/urls.js';
|
|
48
48
|
export type { InteractionUrls, InteractionPostStep, } from './src/interaction/urls.js';
|
|
49
49
|
export { Authenticated, Guest } from './src/components/authenticated.js';
|
|
50
50
|
export type { AuthenticatedProps, GuestProps, } from './src/components/authenticated.js';
|
package/build/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export { usePasskeyAssertion } from './src/hooks/use_passkey_assertion.js';
|
|
|
22
22
|
export { usePasskeyRegistration } from './src/hooks/use_passkey_registration.js';
|
|
23
23
|
export { usePasswordStrength, heuristicScorer, } from './src/hooks/use_password_strength.js';
|
|
24
24
|
export { deriveInitials, currentUrl, buttonClass } from './src/utils.js';
|
|
25
|
-
export { interactionUrls, oauthRedirectUrl } from './src/interaction/urls.js';
|
|
25
|
+
export { interactionUrls, oauthRedirectUrl, OTP_CODE_FIELD } from './src/interaction/urls.js';
|
|
26
26
|
export { Authenticated, Guest } from './src/components/authenticated.js';
|
|
27
27
|
export { CanPermission } from './src/components/can_permission.js';
|
|
28
28
|
export { useCan, checkCan, invalidateCanCache } from './src/hooks/use_can.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FormHTMLAttributes, type ReactNode } from 'react';
|
|
1
|
+
import { type FormHTMLAttributes, type ReactNode, type SubmitEvent } from 'react';
|
|
2
2
|
import { type InteractionPostStep } from '../interaction/urls.js';
|
|
3
3
|
export interface InteractionFormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'method' | 'action'> {
|
|
4
4
|
uid: string;
|
|
@@ -7,7 +7,7 @@ export interface InteractionFormProps extends Omit<FormHTMLAttributes<HTMLFormEl
|
|
|
7
7
|
basePath?: string;
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
}
|
|
10
|
-
export declare function InteractionForm({ uid, step, csrfToken, basePath, children, ...rest }: InteractionFormProps): import("react").DetailedReactHTMLElement<{
|
|
10
|
+
export declare function InteractionForm({ uid, step, csrfToken, basePath, children, onSubmit, ...rest }: InteractionFormProps): import("react").DetailedReactHTMLElement<{
|
|
11
11
|
id?: string | undefined | undefined;
|
|
12
12
|
name?: string | undefined | undefined;
|
|
13
13
|
slot?: string | undefined | undefined;
|
|
@@ -145,7 +145,6 @@ export declare function InteractionForm({ uid, step, csrfToken, basePath, childr
|
|
|
145
145
|
onInputCapture?: import("react").InputEventHandler<HTMLFormElement> | undefined;
|
|
146
146
|
onReset?: import("react").ReactEventHandler<HTMLFormElement> | undefined;
|
|
147
147
|
onResetCapture?: import("react").ReactEventHandler<HTMLFormElement> | undefined;
|
|
148
|
-
onSubmit?: import("react").SubmitEventHandler<HTMLFormElement> | undefined;
|
|
149
148
|
onSubmitCapture?: import("react").SubmitEventHandler<HTMLFormElement> | undefined;
|
|
150
149
|
onInvalid?: import("react").ReactEventHandler<HTMLFormElement> | undefined;
|
|
151
150
|
onInvalidCapture?: import("react").ReactEventHandler<HTMLFormElement> | undefined;
|
|
@@ -295,4 +294,5 @@ export declare function InteractionForm({ uid, step, csrfToken, basePath, childr
|
|
|
295
294
|
target?: string | undefined | undefined;
|
|
296
295
|
method: string;
|
|
297
296
|
action: string;
|
|
297
|
+
onSubmit: (event: SubmitEvent<HTMLElement>) => void;
|
|
298
298
|
}, HTMLElement>;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
1
|
+
import { createElement, } from 'react';
|
|
2
2
|
import { interactionUrls } from '../interaction/urls.js';
|
|
3
|
-
|
|
3
|
+
function lockOnSubmit(event, hostOnSubmit) {
|
|
4
|
+
const formEvent = event;
|
|
5
|
+
hostOnSubmit?.(formEvent);
|
|
6
|
+
const form = formEvent.currentTarget;
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
if (formEvent.defaultPrevented)
|
|
9
|
+
return;
|
|
10
|
+
form
|
|
11
|
+
.querySelectorAll('button[type="submit"], input[type="submit"]')
|
|
12
|
+
.forEach((el) => {
|
|
13
|
+
el.disabled = true;
|
|
14
|
+
});
|
|
15
|
+
form.setAttribute('aria-busy', 'true');
|
|
16
|
+
}, 0);
|
|
17
|
+
}
|
|
18
|
+
export function InteractionForm({ uid, step, csrfToken, basePath, children, onSubmit, ...rest }) {
|
|
4
19
|
const action = interactionUrls(uid, basePath)[step];
|
|
5
|
-
return createElement('form', { method: 'POST', action, ...rest }, createElement('input', { type: 'hidden', name: '_csrf', value: csrfToken }), children);
|
|
20
|
+
return createElement('form', { method: 'POST', action, onSubmit: (event) => lockOnSubmit(event, onSubmit), ...rest }, createElement('input', { type: 'hidden', name: '_csrf', value: csrfToken }), children);
|
|
6
21
|
}
|
|
@@ -3,6 +3,8 @@ export interface MagicLinkButtonProps extends Omit<ButtonHTMLAttributes<HTMLButt
|
|
|
3
3
|
uid: string;
|
|
4
4
|
csrfToken: string;
|
|
5
5
|
basePath?: string;
|
|
6
|
+
channel?: 'code' | 'link';
|
|
7
|
+
pendingChildren?: ReactNode;
|
|
6
8
|
children?: ReactNode;
|
|
7
9
|
}
|
|
8
|
-
export declare function MagicLinkButton({ uid, csrfToken, basePath, children, className, ...rest }: MagicLinkButtonProps): import("react").FunctionComponentElement<import("./interaction_form.js").InteractionFormProps>;
|
|
10
|
+
export declare function MagicLinkButton({ uid, csrfToken, basePath, channel, pendingChildren, children, className, disabled, ...rest }: MagicLinkButtonProps): import("react").FunctionComponentElement<import("./interaction_form.js").InteractionFormProps>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
1
|
+
import { createElement, useState } from 'react';
|
|
2
2
|
import { buttonClass } from '../utils.js';
|
|
3
3
|
import { InteractionForm } from './interaction_form.js';
|
|
4
|
-
export function MagicLinkButton({ uid, csrfToken, basePath, children = 'Enviar link de login', className, ...rest }) {
|
|
5
|
-
|
|
4
|
+
export function MagicLinkButton({ uid, csrfToken, basePath, channel, pendingChildren = 'Enviando…', children = 'Enviar link de login', className, disabled, ...rest }) {
|
|
5
|
+
const [pending, setPending] = useState(false);
|
|
6
|
+
return createElement(InteractionForm, { uid, step: 'magic', csrfToken, basePath, onSubmit: () => setPending(true) }, channel ? createElement('input', { type: 'hidden', name: 'channel', value: channel }) : null, createElement('button', {
|
|
6
7
|
type: 'submit',
|
|
8
|
+
disabled: disabled || pending,
|
|
7
9
|
className: buttonClass('authkit-button--ghost', className),
|
|
8
10
|
...rest,
|
|
9
|
-
}, children));
|
|
11
|
+
}, pending ? pendingChildren : children));
|
|
10
12
|
}
|
|
@@ -6,7 +6,9 @@ export interface InteractionUrls {
|
|
|
6
6
|
switch: string;
|
|
7
7
|
passkeyOptions: string;
|
|
8
8
|
passkeyVerify: string;
|
|
9
|
+
otpVerify: string;
|
|
9
10
|
}
|
|
10
11
|
export declare function interactionUrls(uid: string, basePath?: string): InteractionUrls;
|
|
11
|
-
export type InteractionPostStep = 'identifier' | 'login' | 'magic';
|
|
12
|
+
export type InteractionPostStep = 'identifier' | 'login' | 'magic' | 'otpVerify';
|
|
13
|
+
export declare const OTP_CODE_FIELD = "code";
|
|
12
14
|
export declare function oauthRedirectUrl(provider: string, uid: string, basePath?: string): string;
|
|
@@ -8,8 +8,10 @@ export function interactionUrls(uid, basePath = '/auth/interaction') {
|
|
|
8
8
|
switch: `${base}/switch`,
|
|
9
9
|
passkeyOptions: `${base}/passkey/options`,
|
|
10
10
|
passkeyVerify: `${base}/passkey/verify`,
|
|
11
|
+
otpVerify: `${base}/otp-verify`,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
export const OTP_CODE_FIELD = 'code';
|
|
13
15
|
export function oauthRedirectUrl(provider, uid, basePath = '/auth') {
|
|
14
16
|
return `${basePath}/${provider}/redirect/${uid}`;
|
|
15
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|