@turnkey/sdk-react 3.0.0 → 3.0.2

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 (77) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +470 -0
  4. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -0
  5. package/dist/components/auth/Apple.js +78 -64
  6. package/dist/components/auth/Apple.js.map +1 -1
  7. package/dist/components/auth/Apple.mjs +85 -64
  8. package/dist/components/auth/Apple.mjs.map +1 -1
  9. package/dist/components/auth/Auth.d.ts +3 -0
  10. package/dist/components/auth/Auth.d.ts.map +1 -1
  11. package/dist/components/auth/Auth.js +515 -259
  12. package/dist/components/auth/Auth.js.map +1 -1
  13. package/dist/components/auth/Auth.mjs +741 -231
  14. package/dist/components/auth/Auth.mjs.map +1 -1
  15. package/dist/components/auth/Facebook.js +78 -63
  16. package/dist/components/auth/Facebook.js.map +1 -1
  17. package/dist/components/auth/Facebook.mjs +121 -54
  18. package/dist/components/auth/Facebook.mjs.map +1 -1
  19. package/dist/components/auth/Google.js +63 -47
  20. package/dist/components/auth/Google.js.map +1 -1
  21. package/dist/components/auth/Google.mjs +70 -39
  22. package/dist/components/auth/Google.mjs.map +1 -1
  23. package/dist/components/auth/OtpVerification.d.ts +1 -1
  24. package/dist/components/auth/OtpVerification.d.ts.map +1 -1
  25. package/dist/components/auth/OtpVerification.js +106 -51
  26. package/dist/components/auth/OtpVerification.js.map +1 -1
  27. package/dist/components/auth/OtpVerification.mjs +151 -41
  28. package/dist/components/auth/OtpVerification.mjs.map +1 -1
  29. package/dist/components/auth/PhoneInput.d.ts.map +1 -1
  30. package/dist/components/auth/PhoneInput.js +138 -69
  31. package/dist/components/auth/PhoneInput.js.map +1 -1
  32. package/dist/components/auth/PhoneInput.mjs +141 -70
  33. package/dist/components/auth/PhoneInput.mjs.map +1 -1
  34. package/dist/components/auth/TurnkeyThemeProvider.js +26 -17
  35. package/dist/components/auth/TurnkeyThemeProvider.js.map +1 -1
  36. package/dist/components/auth/TurnkeyThemeProvider.mjs +33 -18
  37. package/dist/components/auth/TurnkeyThemeProvider.mjs.map +1 -1
  38. package/dist/components/auth/constants.js +26 -26
  39. package/dist/components/auth/constants.js.map +1 -1
  40. package/dist/components/auth/constants.mjs +34 -34
  41. package/dist/components/auth/constants.mjs.map +1 -1
  42. package/dist/components/auth/facebookUtils.js +23 -21
  43. package/dist/components/auth/facebookUtils.js.map +1 -1
  44. package/dist/components/auth/facebookUtils.mjs +65 -23
  45. package/dist/components/auth/facebookUtils.mjs.map +1 -1
  46. package/dist/components/auth/otp.js +84 -71
  47. package/dist/components/auth/otp.js.map +1 -1
  48. package/dist/components/auth/otp.mjs +96 -70
  49. package/dist/components/auth/otp.mjs.map +1 -1
  50. package/dist/components/auth/utils.js +3 -3
  51. package/dist/components/auth/utils.js.map +1 -1
  52. package/dist/components/auth/utils.mjs +3 -3
  53. package/dist/components/auth/utils.mjs.map +1 -1
  54. package/dist/components/export/Export.js +181 -99
  55. package/dist/components/export/Export.js.map +1 -1
  56. package/dist/components/export/Export.mjs +257 -89
  57. package/dist/components/export/Export.mjs.map +1 -1
  58. package/dist/components/import/Import.js +185 -132
  59. package/dist/components/import/Import.js.map +1 -1
  60. package/dist/components/import/Import.mjs +264 -120
  61. package/dist/components/import/Import.mjs.map +1 -1
  62. package/dist/contexts/TurnkeyContext.d.ts.map +1 -1
  63. package/dist/contexts/TurnkeyContext.js +113 -93
  64. package/dist/contexts/TurnkeyContext.js.map +1 -1
  65. package/dist/contexts/TurnkeyContext.mjs +191 -92
  66. package/dist/contexts/TurnkeyContext.mjs.map +1 -1
  67. package/dist/hooks/use-session.d.ts.map +1 -1
  68. package/dist/hooks/use-session.js +16 -12
  69. package/dist/hooks/use-session.js.map +1 -1
  70. package/dist/hooks/use-session.mjs +18 -12
  71. package/dist/hooks/use-session.mjs.map +1 -1
  72. package/dist/hooks/use-turnkey.d.ts.map +1 -1
  73. package/dist/hooks/use-turnkey.js +6 -5
  74. package/dist/hooks/use-turnkey.js.map +1 -1
  75. package/dist/hooks/use-turnkey.mjs +7 -6
  76. package/dist/hooks/use-turnkey.mjs.map +1 -1
  77. package/package.json +8 -8
@@ -19,269 +19,525 @@ var useTurnkey = require('../../hooks/use-turnkey.js');
19
19
  var constants = require('./constants.js');
20
20
  var sdkServer = require('@turnkey/sdk-server');
21
21
 
22
- const passkeyIcon = (jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "43", height: "48", fill: "none", children: [jsxRuntime.jsx("path", { fill: "var(--icon-color)", "fill-rule": "evenodd", d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07", "clip-rule": "evenodd" }), jsxRuntime.jsx("path", { fill: "var(--icon-color)", "fill-rule": "evenodd", d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z", "clip-rule": "evenodd" })] }));
23
- const passkeyIconError = (jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "43", height: "48", fill: "none", children: [jsxRuntime.jsx("path", { fill: "var(--error-color)", "fill-rule": "evenodd", d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07", "clip-rule": "evenodd" }), jsxRuntime.jsx("path", { fill: "var(--error-color)", "fill-rule": "evenodd", d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z", "clip-rule": "evenodd" })] }));
24
- const Auth = ({ onAuthSuccess, onError, authConfig, configOrder, customSmsMessage, customAccounts, }) => {
25
- const { passkeyClient, authIframeClient } = useTurnkey.useTurnkey();
26
- const [email, setEmail] = React.useState("");
27
- const [phone, setPhone] = React.useState("");
28
- const [otpId, setOtpId] = React.useState(null);
29
- const [step, setStep] = React.useState("auth");
30
- const [oauthLoading, setOauthLoading] = React.useState("");
31
- const [suborgId, setSuborgId] = React.useState("");
32
- const [passkeySignupScreen, setPasskeySignupScreen] = React.useState(false);
33
- const [passkeyCreationScreen, setPasskeyCreationScreen] = React.useState(false);
34
- const [passkeySignupError, setPasskeySignupError] = React.useState("");
35
- const [loading, setLoading] = React.useState(true);
36
- const [passkeyCreated, setPasskeyCreated] = React.useState(false);
37
- const handleResendCode = async () => {
38
- if (step === constants.OtpType.Email) {
39
- await handleOtpLogin(constants.FilterType.Email, email, constants.OtpType.Email);
40
- }
41
- else if (step === constants.OtpType.Sms) {
42
- await handleOtpLogin(constants.FilterType.PhoneNumber, phone, constants.OtpType.Sms);
43
- }
44
- };
45
- React.useEffect(() => {
46
- if (authIframeClient) {
47
- setLoading(false);
48
- }
49
- }, [authIframeClient]);
50
- if (loading) {
51
- return (jsxRuntime.jsx("div", { className: Auth_module.defaultLoader, children: jsxRuntime.jsx(material.CircularProgress, { size: 80, thickness: 1, className: Auth_module.circularProgress }) }));
22
+ const passkeyIcon = jsxRuntime.jsxs("svg", {
23
+ xmlns: "http://www.w3.org/2000/svg",
24
+ width: "43",
25
+ height: "48",
26
+ fill: "none",
27
+ children: [jsxRuntime.jsx("path", {
28
+ fill: "var(--icon-color)",
29
+ "fill-rule": "evenodd",
30
+ d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07",
31
+ "clip-rule": "evenodd"
32
+ }), jsxRuntime.jsx("path", {
33
+ fill: "var(--icon-color)",
34
+ "fill-rule": "evenodd",
35
+ d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z",
36
+ "clip-rule": "evenodd"
37
+ })]
38
+ });
39
+ const passkeyIconError = jsxRuntime.jsxs("svg", {
40
+ xmlns: "http://www.w3.org/2000/svg",
41
+ width: "43",
42
+ height: "48",
43
+ fill: "none",
44
+ children: [jsxRuntime.jsx("path", {
45
+ fill: "var(--error-color)",
46
+ "fill-rule": "evenodd",
47
+ d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07",
48
+ "clip-rule": "evenodd"
49
+ }), jsxRuntime.jsx("path", {
50
+ fill: "var(--error-color)",
51
+ "fill-rule": "evenodd",
52
+ d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z",
53
+ "clip-rule": "evenodd"
54
+ })]
55
+ });
56
+ const Auth = ({
57
+ onAuthSuccess,
58
+ onError,
59
+ authConfig,
60
+ configOrder,
61
+ customSmsMessage,
62
+ customAccounts
63
+ }) => {
64
+ const {
65
+ passkeyClient,
66
+ authIframeClient,
67
+ turnkey: turnkey$1
68
+ } = useTurnkey.useTurnkey();
69
+ const [email, setEmail] = React.useState("");
70
+ const [phone, setPhone] = React.useState("");
71
+ const [otpId, setOtpId] = React.useState(null);
72
+ const [step, setStep] = React.useState("auth");
73
+ const [oauthLoading, setOauthLoading] = React.useState("");
74
+ const [suborgId, setSuborgId] = React.useState("");
75
+ const [passkeySignupScreen, setPasskeySignupScreen] = React.useState(false);
76
+ const [passkeyCreationScreen, setPasskeyCreationScreen] = React.useState(false);
77
+ const [passkeySignupError, setPasskeySignupError] = React.useState("");
78
+ const [loading, setLoading] = React.useState(true);
79
+ const [passkeyCreated, setPasskeyCreated] = React.useState(false);
80
+ const handleResendCode = async () => {
81
+ if (step === constants.OtpType.Email) {
82
+ await handleOtpLogin(constants.FilterType.Email, email, constants.OtpType.Email);
83
+ } else if (step === constants.OtpType.Sms) {
84
+ await handleOtpLogin(constants.FilterType.PhoneNumber, phone, constants.OtpType.Sms);
52
85
  }
53
- const isValidEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
54
- const isValidPhone = (phone) => /^\+1\d{10}$/.test(phone);
55
- const handleGetOrCreateSuborg = async (filterType, filterValue, additionalData = {}) => {
56
- let suborgId;
57
- if (filterType == constants.FilterType.Email ||
58
- filterType == constants.FilterType.PhoneNumber) {
59
- const getVerifiedSuborgsResponse = await sdkServer.server.getVerifiedSuborgs({
60
- filterType,
61
- filterValue,
62
- });
63
- if (!getVerifiedSuborgsResponse ||
64
- !getVerifiedSuborgsResponse.organizationIds) {
65
- onError(constants.authErrors.suborg.fetchFailed);
66
- }
67
- suborgId = getVerifiedSuborgsResponse?.organizationIds[0];
68
- }
69
- else {
70
- const getSuborgsResponse = await sdkServer.server.getSuborgs({
71
- filterType,
72
- filterValue,
73
- });
74
- if (!getSuborgsResponse || !getSuborgsResponse.organizationIds) {
75
- onError(constants.authErrors.suborg.fetchFailed);
76
- }
77
- suborgId = getSuborgsResponse?.organizationIds[0];
78
- }
79
- if (!suborgId) {
80
- const createSuborgData = { ...additionalData };
81
- if (filterType === constants.FilterType.Email)
82
- createSuborgData.email = filterValue;
83
- else if (filterType === constants.FilterType.PhoneNumber)
84
- createSuborgData.phoneNumber = filterValue;
85
- if (customAccounts) {
86
- createSuborgData.customAccounts = customAccounts;
87
- }
88
- const createSuborgResponse = await sdkServer.server.createSuborg(createSuborgData);
89
- if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
90
- onError(constants.authErrors.suborg.createFailed);
91
- }
92
- suborgId = createSuborgResponse?.subOrganizationId;
93
- }
94
- return suborgId;
95
- };
96
- const handleAuthSuccess = async (credentialBundle) => {
97
- if (credentialBundle) {
98
- await authIframeClient.injectCredentialBundle(credentialBundle);
99
- await authIframeClient.loginWithAuthBundle(credentialBundle);
100
- await onAuthSuccess();
101
- }
102
- };
103
- const handleSignupWithPasskey = async () => {
104
- setPasskeySignupError("");
105
- const siteInfo = `${new URL(window.location.href).hostname} - ${new Date().toLocaleString(undefined, {
106
- year: "numeric",
107
- month: "long",
108
- day: "numeric",
109
- hour: "2-digit",
110
- minute: "2-digit",
111
- second: "2-digit",
112
- })}`;
113
- setPasskeySignupScreen(false);
114
- setPasskeyCreationScreen(true);
115
- try {
116
- if (!passkeyCreated) {
117
- const { encodedChallenge, attestation } = (await passkeyClient?.createUserPasskey({
118
- publicKey: { user: { name: siteInfo, displayName: siteInfo } },
119
- })) || {};
120
- if (encodedChallenge && attestation) {
121
- const response = await sdkServer.server.createSuborg({
122
- email,
123
- passkey: {
124
- authenticatorName: "First Passkey",
125
- challenge: encodedChallenge,
126
- attestation,
127
- },
128
- ...(customAccounts && { customAccounts }),
129
- });
130
- if (response?.subOrganizationId) {
131
- setPasskeyCreated(true);
132
- }
133
- else {
134
- constants.authErrors.passkey.createFailed;
135
- }
136
- }
137
- else {
138
- constants.authErrors.passkey.createFailed;
139
- }
140
- }
141
- const sessionResponse = await passkeyClient?.createReadWriteSession({
142
- targetPublicKey: authIframeClient?.iframePublicKey,
143
- organizationId: process.env.NEXT_PUBLIC_ORGANIZATION_ID,
144
- });
145
- if (sessionResponse?.credentialBundle) {
146
- await handleAuthSuccess(sessionResponse.credentialBundle);
147
- }
148
- else {
149
- setPasskeySignupError(constants.authErrors.passkey.loginFailed);
150
- }
151
- }
152
- catch {
153
- setPasskeySignupError(constants.authErrors.passkey.timeoutOrNotAllowed);
154
- }
155
- };
156
- const handleLoginWithPasskey = async () => {
157
- try {
158
- const sessionResponse = await passkeyClient?.createReadWriteSession({
159
- targetPublicKey: authIframeClient?.iframePublicKey,
160
- organizationId: process.env.NEXT_PUBLIC_ORGANIZATION_ID,
161
- });
162
- if (sessionResponse?.credentialBundle) {
163
- await handleAuthSuccess(sessionResponse.credentialBundle);
164
- }
165
- else {
166
- constants.authErrors.passkey.loginFailed;
86
+ };
87
+ React.useEffect(() => {
88
+ if (authIframeClient) {
89
+ setLoading(false);
90
+ }
91
+ }, [authIframeClient]);
92
+ if (loading) {
93
+ return jsxRuntime.jsx("div", {
94
+ className: Auth_module.defaultLoader,
95
+ children: jsxRuntime.jsx(material.CircularProgress, {
96
+ size: 80,
97
+ thickness: 1,
98
+ className: Auth_module.circularProgress
99
+ })
100
+ });
101
+ }
102
+ const isValidEmail = email => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
103
+ const isValidPhone = phone => /^\+1\d{10}$/.test(phone);
104
+ const handleGetOrCreateSuborg = async (filterType, filterValue, additionalData = {}) => {
105
+ let suborgId;
106
+ if (filterType == constants.FilterType.Email || filterType == constants.FilterType.PhoneNumber) {
107
+ const getVerifiedSuborgsResponse = await sdkServer.server.getVerifiedSuborgs({
108
+ filterType,
109
+ filterValue
110
+ });
111
+ if (!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds) {
112
+ onError(constants.authErrors.suborg.fetchFailed);
113
+ return null;
114
+ }
115
+ suborgId = getVerifiedSuborgsResponse?.organizationIds[0];
116
+ } else {
117
+ const getSuborgsResponse = await sdkServer.server.getSuborgs({
118
+ filterType,
119
+ filterValue
120
+ });
121
+ if (!getSuborgsResponse || !getSuborgsResponse.organizationIds) {
122
+ onError(constants.authErrors.suborg.fetchFailed);
123
+ return null;
124
+ }
125
+ suborgId = getSuborgsResponse?.organizationIds[0];
126
+ }
127
+ if (!suborgId) {
128
+ const createSuborgData = {
129
+ ...additionalData
130
+ };
131
+ if (filterType === constants.FilterType.Email) createSuborgData.email = filterValue;else if (filterType === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = filterValue;
132
+ if (customAccounts) {
133
+ createSuborgData.customAccounts = customAccounts;
134
+ }
135
+ const createSuborgResponse = await sdkServer.server.createSuborg(createSuborgData);
136
+ if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
137
+ onError(constants.authErrors.suborg.createFailed);
138
+ }
139
+ suborgId = createSuborgResponse?.subOrganizationId;
140
+ }
141
+ return suborgId;
142
+ };
143
+ const handleAuthSuccess = async (credentialBundle, expirationSeconds) => {
144
+ if (credentialBundle) {
145
+ await authIframeClient.injectCredentialBundle(credentialBundle);
146
+ await authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
147
+ await onAuthSuccess();
148
+ }
149
+ };
150
+ const handleSignupWithPasskey = async () => {
151
+ setPasskeySignupError("");
152
+ const siteInfo = `${new URL(window.location.href).hostname} - ${new Date().toLocaleString(undefined, {
153
+ year: "numeric",
154
+ month: "long",
155
+ day: "numeric",
156
+ hour: "2-digit",
157
+ minute: "2-digit",
158
+ second: "2-digit"
159
+ })}`;
160
+ setPasskeySignupScreen(false);
161
+ setPasskeyCreationScreen(true);
162
+ try {
163
+ if (!passkeyCreated) {
164
+ const {
165
+ encodedChallenge,
166
+ attestation
167
+ } = (await passkeyClient?.createUserPasskey({
168
+ publicKey: {
169
+ user: {
170
+ name: siteInfo,
171
+ displayName: siteInfo
167
172
  }
173
+ }
174
+ })) || {};
175
+ if (encodedChallenge && attestation) {
176
+ const response = await sdkServer.server.createSuborg({
177
+ email,
178
+ passkey: {
179
+ authenticatorName: "First Passkey",
180
+ challenge: encodedChallenge,
181
+ attestation
182
+ },
183
+ ...(customAccounts && {
184
+ customAccounts
185
+ })
186
+ });
187
+ if (response?.subOrganizationId) {
188
+ setPasskeyCreated(true);
189
+ } else {
190
+ constants.authErrors.passkey.createFailed;
191
+ }
192
+ } else {
193
+ constants.authErrors.passkey.createFailed;
168
194
  }
169
- catch (error) {
170
- onError(constants.authErrors.passkey.loginFailed);
171
- }
172
- };
173
- const handleOtpLogin = async (type, value, otpType) => {
174
- const suborgId = await handleGetOrCreateSuborg(type, value);
175
- const initAuthResponse = await sdkServer.server.sendOtp({
176
- suborgID: suborgId,
177
- otpType,
178
- contact: value,
179
- ...(customSmsMessage && { customSmsMessage }),
180
- userIdentifier: authIframeClient?.iframePublicKey,
181
- });
182
- if (initAuthResponse && initAuthResponse.otpId) {
183
- setSuborgId(suborgId);
184
- setOtpId(initAuthResponse?.otpId);
185
- setStep(otpType);
186
- }
187
- else {
188
- onError(constants.authErrors.otp.sendFailed);
189
- }
190
- };
191
- const handleOAuthLogin = async (credential, providerName) => {
192
- setOauthLoading(providerName);
193
- const suborgId = await handleGetOrCreateSuborg(constants.FilterType.OidcToken, credential, {
194
- oauthProviders: [{ providerName, oidcToken: credential }],
195
- });
196
- const oauthResponse = await sdkServer.server.oauth({
197
- suborgID: suborgId,
198
- oidcToken: credential,
199
- targetPublicKey: authIframeClient?.iframePublicKey,
195
+ }
196
+ const sessionResponse = await passkeyClient?.createReadWriteSession({
197
+ targetPublicKey: authIframeClient?.iframePublicKey,
198
+ ...(authConfig.sessionLengthSeconds !== undefined && {
199
+ expirationSeconds: authConfig.sessionLengthSeconds.toString()
200
+ }),
201
+ organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
202
+ });
203
+ if (sessionResponse?.credentialBundle) {
204
+ await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
205
+ } else {
206
+ setPasskeySignupError(constants.authErrors.passkey.loginFailed);
207
+ }
208
+ } catch {
209
+ setPasskeySignupError(constants.authErrors.passkey.timeoutOrNotAllowed);
210
+ }
211
+ };
212
+ const handleLoginWithPasskey = async () => {
213
+ try {
214
+ const sessionResponse = await passkeyClient?.createReadWriteSession({
215
+ targetPublicKey: authIframeClient?.iframePublicKey,
216
+ ...(authConfig.sessionLengthSeconds !== undefined && {
217
+ expirationSeconds: authConfig.sessionLengthSeconds.toString()
218
+ }),
219
+ organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
220
+ });
221
+ if (sessionResponse?.credentialBundle) {
222
+ await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
223
+ } else {
224
+ constants.authErrors.passkey.loginFailed;
225
+ }
226
+ } catch (error) {
227
+ onError(constants.authErrors.passkey.loginFailed);
228
+ }
229
+ };
230
+ const handleOtpLogin = async (type, value, otpType) => {
231
+ const suborgId = await handleGetOrCreateSuborg(type, value);
232
+ const initAuthResponse = await sdkServer.server.sendOtp({
233
+ suborgID: suborgId,
234
+ otpType,
235
+ contact: value,
236
+ ...(customSmsMessage && {
237
+ customSmsMessage
238
+ }),
239
+ userIdentifier: authIframeClient?.iframePublicKey
240
+ });
241
+ if (initAuthResponse && initAuthResponse.otpId) {
242
+ setSuborgId(suborgId);
243
+ setOtpId(initAuthResponse?.otpId);
244
+ setStep(otpType);
245
+ } else {
246
+ onError(constants.authErrors.otp.sendFailed);
247
+ }
248
+ };
249
+ const handleOAuthLogin = async (credential, providerName) => {
250
+ setOauthLoading(providerName);
251
+ const suborgId = await handleGetOrCreateSuborg(constants.FilterType.OidcToken, credential, {
252
+ oauthProviders: [{
253
+ providerName,
254
+ oidcToken: credential
255
+ }]
256
+ });
257
+ const oauthResponse = await sdkServer.server.oauth({
258
+ suborgID: suborgId,
259
+ oidcToken: credential,
260
+ targetPublicKey: authIframeClient?.iframePublicKey,
261
+ sessionLengthSeconds: authConfig.sessionLengthSeconds
262
+ });
263
+ if (oauthResponse && oauthResponse.token) {
264
+ await handleAuthSuccess(oauthResponse.token, authConfig.sessionLengthSeconds?.toString());
265
+ } else {
266
+ onError(constants.authErrors.oauth.loginFailed);
267
+ }
268
+ };
269
+ const renderBackButton = () => jsxRuntime.jsx(ChevronLeftIcon, {
270
+ onClick: () => {
271
+ setPasskeyCreationScreen(false);
272
+ setPasskeySignupError("");
273
+ setPasskeySignupScreen(false);
274
+ setOtpId(null);
275
+ },
276
+ sx: {
277
+ color: "var(--text-secondary)",
278
+ position: "absolute",
279
+ fontSize: "24px",
280
+ top: 16,
281
+ left: 16,
282
+ zIndex: 10,
283
+ cursor: "pointer",
284
+ borderRadius: "50%",
285
+ padding: "6px",
286
+ transition: "background-color 0.3s ease"
287
+ }
288
+ });
289
+ const renderSocialButtons = () => {
290
+ const {
291
+ googleEnabled,
292
+ appleEnabled,
293
+ facebookEnabled
294
+ } = authConfig;
295
+ const layout = [googleEnabled, appleEnabled, facebookEnabled].filter(Boolean).length >= 2 ? "inline" : "stacked";
296
+ return jsxRuntime.jsxs("div", {
297
+ className: layout === "inline" ? Auth_module.socialButtonContainerInline : Auth_module.socialButtonContainerStacked,
298
+ children: [googleEnabled && jsxRuntime.jsx(Google, {
299
+ layout: layout,
300
+ clientId: authConfig.googleClientId ?? process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
301
+ iframePublicKey: authIframeClient.iframePublicKey,
302
+ onSuccess: response => handleOAuthLogin(response.idToken, "Google")
303
+ }), appleEnabled && jsxRuntime.jsx(Apple, {
304
+ layout: layout,
305
+ clientId: authConfig.appleClientId ?? process.env.NEXT_PUBLIC_APPLE_CLIENT_ID,
306
+ iframePublicKey: authIframeClient.iframePublicKey,
307
+ onSuccess: response => handleOAuthLogin(response.idToken, "Apple")
308
+ }), facebookEnabled && jsxRuntime.jsx(Facebook, {
309
+ layout: layout,
310
+ clientId: authConfig.facebookClientId ?? process.env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID,
311
+ iframePublicKey: authIframeClient.iframePublicKey,
312
+ onSuccess: response => handleOAuthLogin(response.id_token, "Facebook")
313
+ })]
314
+ });
315
+ };
316
+ const renderSection = section => {
317
+ switch (section) {
318
+ case "email":
319
+ return authConfig.emailEnabled && !otpId ? jsxRuntime.jsxs("form", {
320
+ onSubmit: e => {
321
+ e.preventDefault();
322
+ handleOtpLogin(constants.FilterType.Email, email, constants.OtpType.Email);
323
+ },
324
+ children: [jsxRuntime.jsx("div", {
325
+ className: Auth_module.inputGroup,
326
+ children: jsxRuntime.jsx(material.TextField, {
327
+ name: "email-input",
328
+ type: "email",
329
+ placeholder: "Enter your email",
330
+ value: email,
331
+ onChange: e => setEmail(e.target.value),
332
+ fullWidth: true,
333
+ sx: {
334
+ "& .MuiOutlinedInput-root": {
335
+ color: "var(--input-text)",
336
+ "& fieldset": {
337
+ borderColor: "var(--input-border)"
338
+ },
339
+ "&:hover fieldset": {
340
+ borderColor: "var(--input-hover-border)"
341
+ },
342
+ "&.Mui-focused fieldset": {
343
+ borderColor: "var(--input-focus-border)",
344
+ border: "1px solid"
345
+ }
346
+ },
347
+ "& .MuiInputBase-input": {
348
+ padding: "12px"
349
+ },
350
+ backgroundColor: "var(--input-bg)"
351
+ },
352
+ variant: "outlined"
353
+ })
354
+ }), jsxRuntime.jsx("button", {
355
+ className: Auth_module.authButton,
356
+ type: "submit",
357
+ disabled: !isValidEmail(email),
358
+ children: "Continue"
359
+ })]
360
+ }) : null;
361
+ case "phone":
362
+ return authConfig.phoneEnabled && !otpId ? jsxRuntime.jsxs("form", {
363
+ onSubmit: e => {
364
+ e.preventDefault();
365
+ handleOtpLogin(constants.FilterType.PhoneNumber, phone, constants.OtpType.Sms);
366
+ },
367
+ children: [jsxRuntime.jsx("div", {
368
+ className: Auth_module.phoneInput,
369
+ children: jsxRuntime.jsx(PhoneInput.MuiPhone, {
370
+ onChange: value => setPhone(value),
371
+ value: phone
372
+ })
373
+ }), jsxRuntime.jsx("button", {
374
+ className: Auth_module.authButton,
375
+ type: "submit",
376
+ disabled: !isValidPhone(phone),
377
+ children: "Continue"
378
+ })]
379
+ }) : null;
380
+ case "passkey":
381
+ return authConfig.passkeyEnabled && !otpId ? jsxRuntime.jsxs("div", {
382
+ className: Auth_module.passkeyContainer,
383
+ children: [jsxRuntime.jsx("button", {
384
+ className: Auth_module.authButton,
385
+ type: "button",
386
+ onClick: handleLoginWithPasskey,
387
+ children: "Log in with passkey"
388
+ }), jsxRuntime.jsx("div", {
389
+ className: Auth_module.noPasskeyLink,
390
+ onClick: () => setPasskeySignupScreen(true),
391
+ children: "Sign up with passkey"
392
+ })]
393
+ }) : null;
394
+ case "socials":
395
+ return authConfig.googleEnabled || authConfig.appleEnabled || authConfig.facebookEnabled ? renderSocialButtons() : null;
396
+ default:
397
+ return null;
398
+ }
399
+ };
400
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {
401
+ children: passkeySignupScreen ? jsxRuntime.jsxs("div", {
402
+ className: Auth_module.authCard,
403
+ children: [renderBackButton(), jsxRuntime.jsx("div", {
404
+ className: Auth_module.passkeyIconContainer,
405
+ children: passkeyIcon
406
+ }), jsxRuntime.jsx("center", {
407
+ children: jsxRuntime.jsx("h3", {
408
+ className: Auth_module.primaryText,
409
+ children: "Create a passkey"
410
+ })
411
+ }), jsxRuntime.jsx("div", {
412
+ className: Auth_module.rowsContainer,
413
+ children: jsxRuntime.jsx("center", {
414
+ children: jsxRuntime.jsx("span", {
415
+ className: Auth_module.primaryText,
416
+ children: "Passkeys allow for easy biometric access to your wallet and can be synced across devices."
417
+ })
418
+ })
419
+ }), jsxRuntime.jsx("button", {
420
+ className: Auth_module.authButton,
421
+ type: "button",
422
+ onClick: handleSignupWithPasskey,
423
+ children: "Continue"
424
+ })]
425
+ }) : passkeyCreationScreen ? jsxRuntime.jsxs("div", {
426
+ className: Auth_module.authCard,
427
+ children: [renderBackButton(), jsxRuntime.jsx("div", {
428
+ className: Auth_module.passkeyIconContainer,
429
+ children: passkeySignupError ? jsxRuntime.jsx("div", {
430
+ children: passkeyIconError
431
+ }) : jsxRuntime.jsxs("div", {
432
+ className: Auth_module.loadingWrapper,
433
+ children: [jsxRuntime.jsx(material.CircularProgress, {
434
+ size: 80,
435
+ thickness: 1,
436
+ className: Auth_module.circularProgress
437
+ }), passkeyIcon]
438
+ })
439
+ }), jsxRuntime.jsx("center", {
440
+ children: jsxRuntime.jsx("h3", {
441
+ className: Auth_module.primaryText,
442
+ children: passkeySignupError ? "Authentication error" : passkeyCreated ? "Logging in with passkey..." : "Creating passkey..."
443
+ })
444
+ }), jsxRuntime.jsx("div", {
445
+ className: Auth_module.rowsContainer,
446
+ children: jsxRuntime.jsx("span", {
447
+ className: Auth_module.primaryText,
448
+ children: jsxRuntime.jsx("center", {
449
+ children: passkeySignupError ? passkeySignupError : ""
450
+ })
451
+ })
452
+ }), passkeySignupError && jsxRuntime.jsx("button", {
453
+ className: Auth_module.authButton,
454
+ type: "button",
455
+ onClick: handleSignupWithPasskey,
456
+ children: "Retry"
457
+ })]
458
+ }) : jsxRuntime.jsx("div", {
459
+ children: oauthLoading !== "" ? jsxRuntime.jsxs("div", {
460
+ className: Auth_module.authCardLoading,
461
+ children: [jsxRuntime.jsxs("h3", {
462
+ className: Auth_module.verifyingText,
463
+ children: ["Verifying with ", oauthLoading]
464
+ }), jsxRuntime.jsxs("div", {
465
+ className: Auth_module.loadingWrapper,
466
+ children: [jsxRuntime.jsx(material.CircularProgress, {
467
+ size: 80,
468
+ thickness: 1,
469
+ className: Auth_module.circularProgress
470
+ }), oauthLoading === "Google" && jsxRuntime.jsx("img", {
471
+ src: google,
472
+ className: Auth_module.oauthIcon
473
+ }), oauthLoading === "Facebook" && jsxRuntime.jsx("img", {
474
+ src: facebook,
475
+ className: Auth_module.oauthIcon
476
+ }), oauthLoading === "Apple" && jsxRuntime.jsx("img", {
477
+ src: apple,
478
+ className: Auth_module.oauthIcon
479
+ })]
480
+ }), jsxRuntime.jsxs("div", {
481
+ className: Auth_module.poweredBy,
482
+ children: [jsxRuntime.jsx("span", {
483
+ children: "Secured by"
484
+ }), jsxRuntime.jsx("img", {
485
+ src: turnkey
486
+ })]
487
+ })]
488
+ }) : jsxRuntime.jsxs("div", {
489
+ className: Auth_module.authCard,
490
+ children: [otpId && renderBackButton(), jsxRuntime.jsx("h2", {
491
+ className: Auth_module.primaryText,
492
+ children: !otpId && "Log in or sign up"
493
+ }), jsxRuntime.jsxs("div", {
494
+ className: Auth_module.authForm,
495
+ children: [!otpId && configOrder.filter(section => renderSection(section) !== null).map((section, index, visibleSections) => jsxRuntime.jsxs(React.Fragment, {
496
+ children: [renderSection(section), index < visibleSections.length - 1 && jsxRuntime.jsx("div", {
497
+ className: Auth_module.separator,
498
+ children: jsxRuntime.jsx("span", {
499
+ children: "OR"
500
+ })
501
+ })]
502
+ }, section)), otpId && jsxRuntime.jsx(OtpVerification, {
503
+ type: step,
504
+ contact: step === constants.OtpType.Email ? email : phone,
505
+ suborgId: suborgId,
506
+ otpId: otpId,
200
507
  sessionLengthSeconds: authConfig.sessionLengthSeconds,
201
- });
202
- if (oauthResponse && oauthResponse.token) {
203
- await handleAuthSuccess(oauthResponse.token);
204
- }
205
- else {
206
- onError(constants.authErrors.oauth.loginFailed);
207
- }
208
- };
209
- const renderBackButton = () => (jsxRuntime.jsx(ChevronLeftIcon, { onClick: () => {
210
- setPasskeyCreationScreen(false);
211
- setPasskeySignupError("");
212
- setPasskeySignupScreen(false);
213
- setOtpId(null);
214
- }, sx: {
215
- color: "var(--text-secondary)",
216
- position: "absolute",
217
- fontSize: "24px",
218
- top: 16,
219
- left: 16,
220
- zIndex: 10,
221
- cursor: "pointer",
222
- borderRadius: "50%",
223
- padding: "6px",
224
- transition: "background-color 0.3s ease",
225
- } }));
226
- const renderSocialButtons = () => {
227
- const { googleEnabled, appleEnabled, facebookEnabled } = authConfig;
228
- const layout = [googleEnabled, appleEnabled, facebookEnabled].filter(Boolean).length >= 2
229
- ? "inline"
230
- : "stacked";
231
- return (jsxRuntime.jsxs("div", { className: layout === "inline"
232
- ? Auth_module.socialButtonContainerInline
233
- : Auth_module.socialButtonContainerStacked, children: [googleEnabled && (jsxRuntime.jsx(Google, { layout: layout, clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, iframePublicKey: authIframeClient.iframePublicKey, onSuccess: (response) => handleOAuthLogin(response.idToken, "Google") })), appleEnabled && (jsxRuntime.jsx(Apple, { layout: layout, clientId: process.env.NEXT_PUBLIC_APPLE_CLIENT_ID, iframePublicKey: authIframeClient.iframePublicKey, onSuccess: (response) => handleOAuthLogin(response.idToken, "Apple") })), facebookEnabled && (jsxRuntime.jsx(Facebook, { layout: layout, clientId: process.env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID, iframePublicKey: authIframeClient.iframePublicKey, onSuccess: (response) => handleOAuthLogin(response.id_token, "Facebook") }))] }));
234
- };
235
- const renderSection = (section) => {
236
- switch (section) {
237
- case "email":
238
- return authConfig.emailEnabled && !otpId ? (jsxRuntime.jsxs("form", { onSubmit: (e) => {
239
- e.preventDefault();
240
- handleOtpLogin(constants.FilterType.Email, email, constants.OtpType.Email);
241
- }, children: [jsxRuntime.jsx("div", { className: Auth_module.inputGroup, children: jsxRuntime.jsx(material.TextField, { name: "email-input", type: "email", placeholder: "Enter your email", value: email, onChange: (e) => setEmail(e.target.value), fullWidth: true, sx: {
242
- "& .MuiOutlinedInput-root": {
243
- color: "var(--input-text)",
244
- "& fieldset": {
245
- borderColor: "var(--input-border)",
246
- },
247
- "&:hover fieldset": {
248
- borderColor: "var(--input-hover-border)",
249
- },
250
- "&.Mui-focused fieldset": {
251
- borderColor: "var(--input-focus-border)",
252
- border: "1px solid",
253
- },
254
- },
255
- "& .MuiInputBase-input": {
256
- padding: "12px",
257
- },
258
- backgroundColor: "var(--input-bg)",
259
- }, variant: "outlined" }) }), jsxRuntime.jsx("button", { className: Auth_module.authButton, type: "submit", disabled: !isValidEmail(email), children: "Continue" })] })) : null;
260
- case "phone":
261
- return authConfig.phoneEnabled && !otpId ? (jsxRuntime.jsxs("form", { onSubmit: (e) => {
262
- e.preventDefault();
263
- handleOtpLogin(constants.FilterType.PhoneNumber, phone, constants.OtpType.Sms);
264
- }, children: [jsxRuntime.jsx("div", { className: Auth_module.phoneInput, children: jsxRuntime.jsx(PhoneInput.MuiPhone, { onChange: (value) => setPhone(value), value: phone }) }), jsxRuntime.jsx("button", { className: Auth_module.authButton, type: "submit", disabled: !isValidPhone(phone), children: "Continue" })] })) : null;
265
- case "passkey":
266
- return authConfig.passkeyEnabled && !otpId ? (jsxRuntime.jsxs("div", { className: Auth_module.passkeyContainer, children: [jsxRuntime.jsx("button", { className: Auth_module.authButton, type: "button", onClick: handleLoginWithPasskey, children: "Log in with passkey" }), jsxRuntime.jsx("div", { className: Auth_module.noPasskeyLink, onClick: () => setPasskeySignupScreen(true), children: "Sign up with passkey" })] })) : null;
267
- case "socials":
268
- return authConfig.googleEnabled ||
269
- authConfig.appleEnabled ||
270
- authConfig.facebookEnabled
271
- ? renderSocialButtons()
272
- : null;
273
- default:
274
- return null;
275
- }
276
- };
277
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: passkeySignupScreen ? (jsxRuntime.jsxs("div", { className: Auth_module.authCard, children: [renderBackButton(), jsxRuntime.jsx("div", { className: Auth_module.passkeyIconContainer, children: passkeyIcon }), jsxRuntime.jsx("center", { children: jsxRuntime.jsx("h3", { className: Auth_module.primaryText, children: "Create a passkey" }) }), jsxRuntime.jsx("div", { className: Auth_module.rowsContainer, children: jsxRuntime.jsx("center", { children: jsxRuntime.jsx("span", { className: Auth_module.primaryText, children: "Passkeys allow for easy biometric access to your wallet and can be synced across devices." }) }) }), jsxRuntime.jsx("button", { className: Auth_module.authButton, type: "button", onClick: handleSignupWithPasskey, children: "Continue" })] })) : passkeyCreationScreen ? (jsxRuntime.jsxs("div", { className: Auth_module.authCard, children: [renderBackButton(), jsxRuntime.jsx("div", { className: Auth_module.passkeyIconContainer, children: passkeySignupError ? (jsxRuntime.jsx("div", { children: passkeyIconError })) : (jsxRuntime.jsxs("div", { className: Auth_module.loadingWrapper, children: [jsxRuntime.jsx(material.CircularProgress, { size: 80, thickness: 1, className: Auth_module.circularProgress }), passkeyIcon] })) }), jsxRuntime.jsx("center", { children: jsxRuntime.jsx("h3", { className: Auth_module.primaryText, children: passkeySignupError
278
- ? "Authentication error"
279
- : passkeyCreated
280
- ? "Logging in with passkey..."
281
- : "Creating passkey..." }) }), jsxRuntime.jsx("div", { className: Auth_module.rowsContainer, children: jsxRuntime.jsx("span", { className: Auth_module.primaryText, children: jsxRuntime.jsx("center", { children: passkeySignupError ? passkeySignupError : "" }) }) }), passkeySignupError && (jsxRuntime.jsx("button", { className: Auth_module.authButton, type: "button", onClick: handleSignupWithPasskey, children: "Retry" }))] })) : (jsxRuntime.jsx("div", { children: oauthLoading !== "" ? (jsxRuntime.jsxs("div", { className: Auth_module.authCardLoading, children: [jsxRuntime.jsxs("h3", { className: Auth_module.verifyingText, children: ["Verifying with ", oauthLoading] }), jsxRuntime.jsxs("div", { className: Auth_module.loadingWrapper, children: [jsxRuntime.jsx(material.CircularProgress, { size: 80, thickness: 1, className: Auth_module.circularProgress }), oauthLoading === "Google" && (jsxRuntime.jsx("img", { src: google, className: Auth_module.oauthIcon })), oauthLoading === "Facebook" && (jsxRuntime.jsx("img", { src: facebook, className: Auth_module.oauthIcon })), oauthLoading === "Apple" && (jsxRuntime.jsx("img", { src: apple, className: Auth_module.oauthIcon }))] }), jsxRuntime.jsxs("div", { className: Auth_module.poweredBy, children: [jsxRuntime.jsx("span", { children: "Secured by" }), jsxRuntime.jsx("img", { src: turnkey })] })] })) : (jsxRuntime.jsxs("div", { className: Auth_module.authCard, children: [otpId && renderBackButton(), jsxRuntime.jsx("h2", { className: Auth_module.primaryText, children: !otpId && "Log in or sign up" }), jsxRuntime.jsxs("div", { className: Auth_module.authForm, children: [!otpId &&
282
- configOrder
283
- .filter((section) => renderSection(section) !== null)
284
- .map((section, index, visibleSections) => (jsxRuntime.jsxs(React.Fragment, { children: [renderSection(section), index < visibleSections.length - 1 && (jsxRuntime.jsx("div", { className: Auth_module.separator, children: jsxRuntime.jsx("span", { children: "OR" }) }))] }, section))), otpId && (jsxRuntime.jsx(OtpVerification, { type: step, contact: step === constants.OtpType.Email ? email : phone, suborgId: suborgId, otpId: otpId, sessionLengthSeconds: authConfig.sessionLengthSeconds, authIframeClient: authIframeClient, onValidateSuccess: handleAuthSuccess, onResendCode: handleResendCode })), !otpId && (jsxRuntime.jsx("div", { className: Auth_module.tos, children: jsxRuntime.jsxs("span", { children: ["By continuing, you agree to our", " ", jsxRuntime.jsx("a", { href: "https://www.turnkey.com/legal/terms", target: "_blank", rel: "noopener noreferrer", className: Auth_module.tosBold, children: "Terms of Service" }), " ", "&", " ", jsxRuntime.jsx("a", { href: "https://www.turnkey.com/legal/privacy", target: "_blank", rel: "noopener noreferrer", className: Auth_module.tosBold, children: "Privacy Policy" }), "."] }) }))] }), jsxRuntime.jsxs("div", { onClick: () => (window.location.href = "https://www.turnkey.com/"), className: Auth_module.poweredBy, children: [jsxRuntime.jsx("span", { children: "Secured by" }), jsxRuntime.jsx("img", { src: turnkey })] })] })) })) }));
508
+ authIframeClient: authIframeClient,
509
+ onValidateSuccess: handleAuthSuccess,
510
+ onResendCode: handleResendCode
511
+ }), !otpId && jsxRuntime.jsx("div", {
512
+ className: Auth_module.tos,
513
+ children: jsxRuntime.jsxs("span", {
514
+ children: ["By continuing, you agree to our", " ", jsxRuntime.jsx("a", {
515
+ href: "https://www.turnkey.com/legal/terms",
516
+ target: "_blank",
517
+ rel: "noopener noreferrer",
518
+ className: Auth_module.tosBold,
519
+ children: "Terms of Service"
520
+ }), " ", "&", " ", jsxRuntime.jsx("a", {
521
+ href: "https://www.turnkey.com/legal/privacy",
522
+ target: "_blank",
523
+ rel: "noopener noreferrer",
524
+ className: Auth_module.tosBold,
525
+ children: "Privacy Policy"
526
+ }), "."]
527
+ })
528
+ })]
529
+ }), jsxRuntime.jsxs("div", {
530
+ onClick: () => window.location.href = "https://www.turnkey.com/",
531
+ className: Auth_module.poweredBy,
532
+ children: [jsxRuntime.jsx("span", {
533
+ children: "Secured by"
534
+ }), jsxRuntime.jsx("img", {
535
+ src: turnkey
536
+ })]
537
+ })]
538
+ })
539
+ })
540
+ });
285
541
  };
286
542
 
287
543
  module.exports = Auth;