@dloizides/auth-web 1.5.0 → 1.6.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/dist/index.d.mts +150 -85
- package/dist/index.d.ts +150 -85
- package/dist/index.js +151 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +110 -110
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,117 @@
|
|
|
1
|
-
import { createContext, useState, useRef, useEffect, useCallback, useMemo, useContext } from 'react';
|
|
2
1
|
import { StyleSheet, View, Text, TextInput, TouchableOpacity, ActivityIndicator, Pressable } from 'react-native';
|
|
2
|
+
import { createContext, useContext, useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useMutation } from '@tanstack/react-query';
|
|
5
5
|
import { BffAuthClient, createFetchHttpClient } from '@dloizides/auth-client';
|
|
6
6
|
export { BffAuthClient, createFetchHttpClient } from '@dloizides/auth-client';
|
|
7
7
|
|
|
8
|
-
// src/components/
|
|
8
|
+
// src/components/AuthScreen.tsx
|
|
9
|
+
var FULL_WIDTH = "100%";
|
|
10
|
+
var CARD_BORDER_WIDTH = 1;
|
|
11
|
+
function useAuthScreenStyles(theme) {
|
|
12
|
+
return useMemo(() => {
|
|
13
|
+
const { colors, radii, spacing, typography } = theme;
|
|
14
|
+
return StyleSheet.create({
|
|
15
|
+
screen: {
|
|
16
|
+
flex: 1,
|
|
17
|
+
justifyContent: "center",
|
|
18
|
+
alignItems: "center",
|
|
19
|
+
padding: spacing.md,
|
|
20
|
+
backgroundColor: colors.background
|
|
21
|
+
},
|
|
22
|
+
card: {
|
|
23
|
+
width: FULL_WIDTH,
|
|
24
|
+
borderRadius: radii.card,
|
|
25
|
+
borderWidth: CARD_BORDER_WIDTH,
|
|
26
|
+
borderColor: colors.border,
|
|
27
|
+
padding: spacing.xl,
|
|
28
|
+
backgroundColor: colors.surface
|
|
29
|
+
},
|
|
30
|
+
title: {
|
|
31
|
+
fontSize: typography.title,
|
|
32
|
+
fontWeight: "bold",
|
|
33
|
+
marginBottom: spacing.xs,
|
|
34
|
+
color: colors.text
|
|
35
|
+
},
|
|
36
|
+
subtitle: {
|
|
37
|
+
fontSize: typography.subtitle,
|
|
38
|
+
marginBottom: spacing.lg,
|
|
39
|
+
color: colors.textSecondary
|
|
40
|
+
},
|
|
41
|
+
footer: {
|
|
42
|
+
marginTop: spacing.lg,
|
|
43
|
+
width: FULL_WIDTH,
|
|
44
|
+
alignItems: "center"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [theme]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/theme/AuthTheme.ts
|
|
51
|
+
var defaultAuthTheme = {
|
|
52
|
+
colors: {
|
|
53
|
+
background: "#f5f5f7",
|
|
54
|
+
surface: "#ffffff",
|
|
55
|
+
text: "#1a1a1a",
|
|
56
|
+
textSecondary: "#6b6b6b",
|
|
57
|
+
border: "#d0d0d5",
|
|
58
|
+
primary: "#2563eb",
|
|
59
|
+
onPrimary: "#ffffff",
|
|
60
|
+
danger: "#d33333",
|
|
61
|
+
success: "#1f7a3d"
|
|
62
|
+
},
|
|
63
|
+
radii: {
|
|
64
|
+
input: 8,
|
|
65
|
+
card: 12
|
|
66
|
+
},
|
|
67
|
+
spacing: {
|
|
68
|
+
xs: 8,
|
|
69
|
+
sm: 12,
|
|
70
|
+
md: 20,
|
|
71
|
+
lg: 32,
|
|
72
|
+
xl: 24
|
|
73
|
+
},
|
|
74
|
+
typography: {
|
|
75
|
+
title: 28,
|
|
76
|
+
subtitle: 16,
|
|
77
|
+
label: 14,
|
|
78
|
+
body: 16,
|
|
79
|
+
caption: 12
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var AuthThemeContext = createContext(defaultAuthTheme);
|
|
83
|
+
function AuthThemeProvider({
|
|
84
|
+
theme,
|
|
85
|
+
children
|
|
86
|
+
}) {
|
|
87
|
+
return /* @__PURE__ */ jsx(AuthThemeContext.Provider, { value: theme, children });
|
|
88
|
+
}
|
|
89
|
+
function useAuthTheme(themeProp) {
|
|
90
|
+
const contextTheme = useContext(AuthThemeContext);
|
|
91
|
+
return useMemo(() => themeProp ?? contextTheme, [themeProp, contextTheme]);
|
|
92
|
+
}
|
|
93
|
+
var DEFAULT_AUTH_CARD_MAX_WIDTH = 420;
|
|
94
|
+
function AuthScreen({
|
|
95
|
+
children,
|
|
96
|
+
theme: themeProp,
|
|
97
|
+
testID,
|
|
98
|
+
cardTestID,
|
|
99
|
+
maxWidth = DEFAULT_AUTH_CARD_MAX_WIDTH,
|
|
100
|
+
title,
|
|
101
|
+
subtitle,
|
|
102
|
+
footer
|
|
103
|
+
}) {
|
|
104
|
+
const theme = useAuthTheme(themeProp);
|
|
105
|
+
const styles3 = useAuthScreenStyles(theme);
|
|
106
|
+
return /* @__PURE__ */ jsxs(View, { style: styles3.screen, testID, children: [
|
|
107
|
+
/* @__PURE__ */ jsxs(View, { style: [styles3.card, { maxWidth }], testID: cardTestID, children: [
|
|
108
|
+
title !== void 0 ? /* @__PURE__ */ jsx(Text, { style: styles3.title, children: title }) : null,
|
|
109
|
+
subtitle !== void 0 ? /* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: subtitle }) : null,
|
|
110
|
+
children
|
|
111
|
+
] }),
|
|
112
|
+
footer !== void 0 ? /* @__PURE__ */ jsx(View, { style: [styles3.footer, { maxWidth }], children: footer }) : null
|
|
113
|
+
] });
|
|
114
|
+
}
|
|
9
115
|
|
|
10
116
|
// src/components/labels.ts
|
|
11
117
|
var DEFAULT_LOGIN_LABELS = {
|
|
@@ -246,7 +352,7 @@ var AuthTestIds = {
|
|
|
246
352
|
function withTestIdPrefix(baseId, prefix) {
|
|
247
353
|
return prefix === void 0 || prefix === "" ? baseId : `${prefix}-${baseId}`;
|
|
248
354
|
}
|
|
249
|
-
var
|
|
355
|
+
var FULL_WIDTH2 = "100%";
|
|
250
356
|
var CARD_MAX_WIDTH = 420;
|
|
251
357
|
var BUTTON_VERTICAL_PADDING = 14;
|
|
252
358
|
function useAuthStyles(theme) {
|
|
@@ -261,7 +367,7 @@ function useAuthStyles(theme) {
|
|
|
261
367
|
backgroundColor: colors.background
|
|
262
368
|
},
|
|
263
369
|
card: {
|
|
264
|
-
width:
|
|
370
|
+
width: FULL_WIDTH2,
|
|
265
371
|
maxWidth: CARD_MAX_WIDTH,
|
|
266
372
|
borderRadius: radii.card,
|
|
267
373
|
padding: spacing.xl,
|
|
@@ -468,50 +574,6 @@ function useBffAuth(options) {
|
|
|
468
574
|
[session.user, session.status, isSubmitting, error, login, logout, refresh]
|
|
469
575
|
);
|
|
470
576
|
}
|
|
471
|
-
|
|
472
|
-
// src/theme/AuthTheme.ts
|
|
473
|
-
var defaultAuthTheme = {
|
|
474
|
-
colors: {
|
|
475
|
-
background: "#f5f5f7",
|
|
476
|
-
surface: "#ffffff",
|
|
477
|
-
text: "#1a1a1a",
|
|
478
|
-
textSecondary: "#6b6b6b",
|
|
479
|
-
border: "#d0d0d5",
|
|
480
|
-
primary: "#2563eb",
|
|
481
|
-
onPrimary: "#ffffff",
|
|
482
|
-
danger: "#d33333",
|
|
483
|
-
success: "#1f7a3d"
|
|
484
|
-
},
|
|
485
|
-
radii: {
|
|
486
|
-
input: 8,
|
|
487
|
-
card: 12
|
|
488
|
-
},
|
|
489
|
-
spacing: {
|
|
490
|
-
xs: 8,
|
|
491
|
-
sm: 12,
|
|
492
|
-
md: 20,
|
|
493
|
-
lg: 32,
|
|
494
|
-
xl: 24
|
|
495
|
-
},
|
|
496
|
-
typography: {
|
|
497
|
-
title: 28,
|
|
498
|
-
subtitle: 16,
|
|
499
|
-
label: 14,
|
|
500
|
-
body: 16,
|
|
501
|
-
caption: 12
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
var AuthThemeContext = createContext(defaultAuthTheme);
|
|
505
|
-
function AuthThemeProvider({
|
|
506
|
-
theme,
|
|
507
|
-
children
|
|
508
|
-
}) {
|
|
509
|
-
return /* @__PURE__ */ jsx(AuthThemeContext.Provider, { value: theme, children });
|
|
510
|
-
}
|
|
511
|
-
function useAuthTheme(themeProp) {
|
|
512
|
-
const contextTheme = useContext(AuthThemeContext);
|
|
513
|
-
return useMemo(() => themeProp ?? contextTheme, [themeProp, contextTheme]);
|
|
514
|
-
}
|
|
515
577
|
function LoginForm({
|
|
516
578
|
client,
|
|
517
579
|
theme: themeProp,
|
|
@@ -519,7 +581,8 @@ function LoginForm({
|
|
|
519
581
|
onSuccess,
|
|
520
582
|
onForgotPassword,
|
|
521
583
|
onSignUp,
|
|
522
|
-
testIdPrefix
|
|
584
|
+
testIdPrefix,
|
|
585
|
+
chromeless = false
|
|
523
586
|
}) {
|
|
524
587
|
const theme = useAuthTheme(themeProp);
|
|
525
588
|
const styles3 = useAuthStyles(theme);
|
|
@@ -550,7 +613,7 @@ function LoginForm({
|
|
|
550
613
|
void runLogin();
|
|
551
614
|
}, [runLogin]);
|
|
552
615
|
const submitButtonStyle = isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
|
|
553
|
-
|
|
616
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
554
617
|
/* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
|
|
555
618
|
/* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.subtitle }),
|
|
556
619
|
/* @__PURE__ */ jsxs(View, { style: styles3.fieldGroup, children: [
|
|
@@ -639,7 +702,16 @@ function LoginForm({
|
|
|
639
702
|
children: /* @__PURE__ */ jsx(Text, { style: styles3.linkText, children: labels.signUp })
|
|
640
703
|
}
|
|
641
704
|
) : null
|
|
642
|
-
] })
|
|
705
|
+
] });
|
|
706
|
+
const card = /* @__PURE__ */ jsx(
|
|
707
|
+
View,
|
|
708
|
+
{
|
|
709
|
+
style: chromeless ? void 0 : styles3.card,
|
|
710
|
+
testID: withTestIdPrefix(AuthTestIds.loginForm, testIdPrefix),
|
|
711
|
+
children: content
|
|
712
|
+
}
|
|
713
|
+
);
|
|
714
|
+
return chromeless ? card : /* @__PURE__ */ jsx(View, { style: styles3.screen, children: card });
|
|
643
715
|
}
|
|
644
716
|
function useBffForgotPassword(options) {
|
|
645
717
|
const { client, ...rest } = options;
|
|
@@ -1489,7 +1561,8 @@ function OtpForm({
|
|
|
1489
1561
|
theme: themeProp,
|
|
1490
1562
|
labels: labelsProp,
|
|
1491
1563
|
onSuccess,
|
|
1492
|
-
testIdPrefix
|
|
1564
|
+
testIdPrefix,
|
|
1565
|
+
chromeless = false
|
|
1493
1566
|
}) {
|
|
1494
1567
|
const theme = useAuthTheme(themeProp);
|
|
1495
1568
|
const styles3 = useAuthStyles(theme);
|
|
@@ -1510,7 +1583,7 @@ function OtpForm({
|
|
|
1510
1583
|
otp.reset();
|
|
1511
1584
|
}, [otp]);
|
|
1512
1585
|
const errorText = localError ?? transportErrorFor(otp.step, otp.error, labels);
|
|
1513
|
-
|
|
1586
|
+
const content = otp.step === "requestCode" /* RequestCode */ ? /* @__PURE__ */ jsx(
|
|
1514
1587
|
OtpRequestStep,
|
|
1515
1588
|
{
|
|
1516
1589
|
errorText,
|
|
@@ -1535,7 +1608,16 @@ function OtpForm({
|
|
|
1535
1608
|
onResend: handleResend,
|
|
1536
1609
|
onSubmit: handleVerify
|
|
1537
1610
|
}
|
|
1538
|
-
)
|
|
1611
|
+
);
|
|
1612
|
+
const card = /* @__PURE__ */ jsx(
|
|
1613
|
+
View,
|
|
1614
|
+
{
|
|
1615
|
+
style: chromeless ? void 0 : styles3.card,
|
|
1616
|
+
testID: withTestIdPrefix(AuthTestIds.otpForm, testIdPrefix),
|
|
1617
|
+
children: content
|
|
1618
|
+
}
|
|
1619
|
+
);
|
|
1620
|
+
return chromeless ? card : /* @__PURE__ */ jsx(View, { style: styles3.screen, children: card });
|
|
1539
1621
|
}
|
|
1540
1622
|
function toError3(value) {
|
|
1541
1623
|
return value instanceof Error ? value : new Error(String(value));
|
|
@@ -1614,7 +1696,8 @@ function PinForm({
|
|
|
1614
1696
|
theme: themeProp,
|
|
1615
1697
|
labels: labelsProp,
|
|
1616
1698
|
onSuccess,
|
|
1617
|
-
testIdPrefix
|
|
1699
|
+
testIdPrefix,
|
|
1700
|
+
chromeless = false
|
|
1618
1701
|
}) {
|
|
1619
1702
|
const theme = useAuthTheme(themeProp);
|
|
1620
1703
|
const styles3 = useAuthStyles(theme);
|
|
@@ -1628,7 +1711,7 @@ function PinForm({
|
|
|
1628
1711
|
const handleSubmit = useSubmitHandler(pin, labels, setLocalError, onSuccess);
|
|
1629
1712
|
const errorText = localError ?? transportErrorFor2(pin.error, labels);
|
|
1630
1713
|
const buttonStyle = pin.isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
|
|
1631
|
-
|
|
1714
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1632
1715
|
/* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
|
|
1633
1716
|
/* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.description }),
|
|
1634
1717
|
/* @__PURE__ */ jsxs(View, { style: styles3.fieldGroup, children: [
|
|
@@ -1673,7 +1756,16 @@ function PinForm({
|
|
|
1673
1756
|
children: pin.isSubmitting ? /* @__PURE__ */ jsx(ActivityIndicator, { color: theme.colors.onPrimary, size: "small" }) : /* @__PURE__ */ jsx(Text, { style: styles3.primaryButtonText, children: labels.submit })
|
|
1674
1757
|
}
|
|
1675
1758
|
)
|
|
1676
|
-
] })
|
|
1759
|
+
] });
|
|
1760
|
+
const card = /* @__PURE__ */ jsx(
|
|
1761
|
+
View,
|
|
1762
|
+
{
|
|
1763
|
+
style: chromeless ? void 0 : styles3.card,
|
|
1764
|
+
testID: withTestIdPrefix(AuthTestIds.pinForm, testIdPrefix),
|
|
1765
|
+
children: content
|
|
1766
|
+
}
|
|
1767
|
+
);
|
|
1768
|
+
return chromeless ? card : /* @__PURE__ */ jsx(View, { style: styles3.screen, children: card });
|
|
1677
1769
|
}
|
|
1678
1770
|
var DOT_SIZE = 18;
|
|
1679
1771
|
var DOT_BORDER_WIDTH = 2;
|
|
@@ -2907,6 +2999,6 @@ function resolvePostLoginRoute(user, table) {
|
|
|
2907
2999
|
return table.fallback ?? null;
|
|
2908
3000
|
}
|
|
2909
3001
|
|
|
2910
|
-
export { AuthTestIds, AuthThemeProvider, BffAuthStatus, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, ResetPasswordError, ResetPasswordForm, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createPreferencesClient, defaultAuthTheme, isAllowedPinDigits, isPasswordValid, isValidForgotPasswordEmail, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, resolvePostLoginRoute, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePinLogin, usePreferredMethodSetting, useResetPasswordForm, validatePasswordPolicy, withTestIdPrefix };
|
|
3002
|
+
export { AuthScreen, AuthTestIds, AuthThemeProvider, BffAuthStatus, DEFAULT_AUTH_CARD_MAX_WIDTH, DEFAULT_DEVICE_PIN_ENROLL_LABELS, DEFAULT_DEVICE_PIN_SETTINGS_LABELS, DEFAULT_DEVICE_PIN_UNLOCK_LABELS, DEFAULT_FORGOT_PASSWORD_FIELDS_LABELS, DEFAULT_FORGOT_PASSWORD_LABELS, DEFAULT_LOGIN_LABELS, DEFAULT_OTP_LABELS, DEFAULT_PASSKEY_LOGIN_LABELS, DEFAULT_PASSKEY_SETTINGS_LABELS, DEFAULT_PIN_LABELS, DEFAULT_PREFERRED_METHOD_HINT_LABELS, DEFAULT_PREFERRED_METHOD_SETTINGS_LABELS, DEFAULT_RESET_PASSWORD_LABELS, DEVICE_PIN_ALLOWED_DIGITS, DEVICE_PIN_DEFAULT_DIGITS, DevicePinEnrollErrorKey, DevicePinEnrollForm, DevicePinErrorKey, DevicePinInput, DevicePinLengthPicker, DevicePinOffer, DevicePinSettingsCard, DevicePinUnlockScreen, ForgotPasswordFields, ForgotPasswordForm, LoginForm, OtpForm, OtpLoginStep, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PasskeyLoginButton, PasskeySettingsCard, PasswordPolicyError, PinForm, PreferredMethodHint, PreferredMethodSettingsCard, ResetPasswordError, ResetPasswordForm, cachePreferredMethod, clearCachedPreferredMethod, collectUserRoles, createBffAuthClient, createPreferencesClient, defaultAuthTheme, isAllowedPinDigits, isPasswordValid, isValidForgotPasswordEmail, readCachedPreferredMethod, readPasskeyError, readPasskeyRegistered, resolvePostLoginRoute, startPasskeyLogin, startPasskeyRegistration, syncPreferredMethodFromServer, useAuthTheme, useBffAuth, useBffForgotPassword, useBffLoginConfig, useBffResetPassword, useDevicePinDisable, useDevicePinEnroll, useDevicePinUnlock, useForgotPasswordSubmit, useOtpLogin, usePinLogin, usePreferredMethodSetting, useResetPasswordForm, validatePasswordPolicy, withTestIdPrefix };
|
|
2911
3003
|
//# sourceMappingURL=index.mjs.map
|
|
2912
3004
|
//# sourceMappingURL=index.mjs.map
|