@stytch/react 20.0.0-next.2 → 20.0.0-next.4
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 +12 -0
- package/dist/cjs/StytchSSRProxy-Bz6LNYdq.js.map +1 -1
- package/dist/cjs/adminPortal/index.cjs +1 -1
- package/dist/cjs/b2b/index.cjs +28 -20
- package/dist/cjs/b2b/index.cjs.map +1 -1
- package/dist/cjs/compat.cjs +2 -0
- package/dist/cjs/compat.cjs.map +1 -1
- package/dist/cjs/{index-Ni_dyEsz.js → index-BIjXBvf_.js} +2 -2
- package/dist/cjs/index-BIjXBvf_.js.map +1 -0
- package/dist/cjs/index.cjs +521 -542
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{shadcn-B8TEzQMT.js → shadcn-aVU6Lm9q.js} +255 -235
- package/dist/cjs/shadcn-aVU6Lm9q.js.map +1 -0
- package/dist/cjs-dev/StytchSSRProxy-d553KgcY.js +438 -0
- package/dist/cjs-dev/StytchSSRProxy-d553KgcY.js.map +1 -0
- package/dist/cjs-dev/adminPortal/index.cjs +54 -53
- package/dist/cjs-dev/adminPortal/index.cjs.map +1 -1
- package/dist/cjs-dev/b2b/index.cjs +94 -75
- package/dist/cjs-dev/b2b/index.cjs.map +1 -1
- package/dist/cjs-dev/b2b/index.headless.cjs +89 -88
- package/dist/cjs-dev/b2b/index.headless.cjs.map +1 -1
- package/dist/cjs-dev/compat.cjs +15 -14
- package/dist/cjs-dev/compat.cjs.map +1 -1
- package/dist/cjs-dev/{StytchSSRProxy-CxXsyme4.js → dev-DaCGDI6V.js} +60 -426
- package/dist/cjs-dev/dev-DaCGDI6V.js.map +1 -0
- package/dist/cjs-dev/{idpHelpers-BVMUYvt1.js → idpHelpers-DOYYSxsX.js} +45 -102
- package/dist/cjs-dev/idpHelpers-DOYYSxsX.js.map +1 -0
- package/dist/cjs-dev/{index-DdK3Jt4u.js → index-rquGmIlv.js} +4 -4
- package/dist/cjs-dev/index-rquGmIlv.js.map +1 -0
- package/dist/cjs-dev/index.cjs +667 -667
- package/dist/cjs-dev/index.cjs.map +1 -1
- package/dist/cjs-dev/index.headless.cjs +70 -69
- package/dist/cjs-dev/index.headless.cjs.map +1 -1
- package/dist/cjs-dev/{passwordManagerDisableAutofillProps-D70WyvIu.js → passwordManagerDisableAutofillProps-CgiK2M_U.js} +2 -2
- package/dist/cjs-dev/{passwordManagerDisableAutofillProps-D70WyvIu.js.map → passwordManagerDisableAutofillProps-CgiK2M_U.js.map} +1 -1
- package/dist/cjs-dev/{shadcn-C9ClUju1.js → shadcn-DMk6ZSoD.js} +265 -244
- package/dist/cjs-dev/shadcn-DMk6ZSoD.js.map +1 -0
- package/dist/esm/_virtual/index3.mjs +5 -3
- package/dist/esm/_virtual/index3.mjs.map +1 -1
- package/dist/esm/_virtual/index4.mjs +3 -5
- package/dist/esm/_virtual/index4.mjs.map +1 -1
- package/dist/esm/b2b/StytchB2BContext.mjs +5 -5
- package/dist/esm/b2b/StytchB2BContext.mjs.map +1 -1
- package/dist/esm/packages/core/src/public/b2b/ui.mjs.map +1 -1
- package/dist/esm/packages/web/src/adminPortal/utils/theme.mjs +1 -1
- package/dist/esm/packages/web/src/ui/b2b/App.mjs +2 -2
- package/dist/esm/packages/web/src/ui/b2b/App.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2b/components/Icons.mjs +3 -1
- package/dist/esm/packages/web/src/ui/b2b/components/Icons.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2b/components/OAuthB2BButton.mjs +6 -3
- package/dist/esm/packages/web/src/ui/b2b/components/OAuthB2BButton.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2b/components/SSOButton.mjs +5 -3
- package/dist/esm/packages/web/src/ui/b2b/components/SSOButton.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2b/screens/SsoAndOAuthButtons.mjs +6 -3
- package/dist/esm/packages/web/src/ui/b2b/screens/SsoAndOAuthButtons.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2b/types/authMethodKeys.mjs +2 -2
- package/dist/esm/packages/web/src/ui/b2b/types/authMethodKeys.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/AppContainer.mjs +1 -1
- package/dist/esm/packages/web/src/ui/b2c/AppContainer.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/IDPContainer.mjs +1 -1
- package/dist/esm/packages/web/src/ui/b2c/IDPContainer.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/PasskeyRegistrationContainer.mjs +1 -1
- package/dist/esm/packages/web/src/ui/b2c/PasskeyRegistrationContainer.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/ResetPasswordContainer.mjs +1 -1
- package/dist/esm/packages/web/src/ui/b2c/ResetPasswordContainer.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/components/OAuthButton.mjs +6 -3
- package/dist/esm/packages/web/src/ui/b2c/components/OAuthButton.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/screens/Crypto/SetupNewWallet.mjs +20 -39
- package/dist/esm/packages/web/src/ui/b2c/screens/Crypto/SetupNewWallet.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/b2c/screens/Crypto/WalletButtons.mjs +15 -15
- package/dist/esm/packages/web/src/ui/b2c/screens/Crypto/WalletButtons.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/compat/styleToTheme.mjs +2 -0
- package/dist/esm/packages/web/src/ui/compat/styleToTheme.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/components/PresentationConfig.mjs +6 -1
- package/dist/esm/packages/web/src/ui/components/PresentationConfig.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/components/atoms/Button.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/components/atoms/Typography.module.css.mjs +2 -2
- package/dist/esm/packages/web/src/ui/components/molecules/EmailInput.mjs +1 -1
- package/dist/esm/packages/web/src/ui/components/molecules/EmailInput.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/components/molecules/Input.mjs +1 -1
- package/dist/esm/packages/web/src/ui/components/molecules/Input.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/B2BIdentityProvider.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/B2BIdentityProvider.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/Stytch.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/Stytch.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/StytchB2BContext.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2b/StytchB2BContext.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/IdentityProvider.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/IdentityProvider.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchContext.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchContext.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchLogin.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchLogin.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchPasskeyRegistration.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchPasskeyRegistration.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchPasswordReset.mjs +1 -1
- package/dist/esm/packages/web/src/ui/react/b2c/StytchPasswordReset.mjs.map +1 -1
- package/dist/esm/packages/web/src/ui/react/utils/errors.mjs.map +1 -1
- package/dist/esm/packages/web/src/utils/crypto.mjs +19 -14
- package/dist/esm/packages/web/src/utils/crypto.mjs.map +1 -1
- package/dist/esm/packages/web/src/utils/oauthProviderType.mjs +1 -1
- package/dist/esm/packages/web/src/utils/oauthProviderType.mjs.map +1 -1
- package/dist/esm-dev/_virtual/index3.mjs +3 -5
- package/dist/esm-dev/_virtual/index3.mjs.map +1 -1
- package/dist/esm-dev/_virtual/index4.mjs +5 -3
- package/dist/esm-dev/_virtual/index4.mjs.map +1 -1
- package/dist/esm-dev/b2b/StytchB2BContext.mjs +5 -5
- package/dist/esm-dev/b2b/StytchB2BContext.mjs.map +1 -1
- package/dist/esm-dev/packages/core/src/public/b2b/ui.mjs.map +1 -1
- package/dist/esm-dev/packages/core/src/utils/dev.mjs +7 -1
- package/dist/esm-dev/packages/core/src/utils/dev.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/adminPortal/utils/theme.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/App.mjs +14 -2
- package/dist/esm-dev/packages/web/src/ui/b2b/App.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/components/Icons.mjs +3 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/components/Icons.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/components/OAuthB2BButton.mjs +6 -3
- package/dist/esm-dev/packages/web/src/ui/b2b/components/OAuthB2BButton.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/components/SSOButton.mjs +5 -3
- package/dist/esm-dev/packages/web/src/ui/b2b/components/SSOButton.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/screens/SsoAndOAuthButtons.mjs +6 -3
- package/dist/esm-dev/packages/web/src/ui/b2b/screens/SsoAndOAuthButtons.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2b/types/authMethodKeys.mjs +2 -2
- package/dist/esm-dev/packages/web/src/ui/b2b/types/authMethodKeys.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/AppContainer.mjs +8 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/AppContainer.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/IDPContainer.mjs +8 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/IDPContainer.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/PasskeyRegistrationContainer.mjs +8 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/PasskeyRegistrationContainer.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/ResetPasswordContainer.mjs +8 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/ResetPasswordContainer.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/components/OAuthButton.mjs +6 -3
- package/dist/esm-dev/packages/web/src/ui/b2c/components/OAuthButton.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/screens/Crypto/SetupNewWallet.mjs +20 -39
- package/dist/esm-dev/packages/web/src/ui/b2c/screens/Crypto/SetupNewWallet.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/b2c/screens/Crypto/WalletButtons.mjs +15 -15
- package/dist/esm-dev/packages/web/src/ui/b2c/screens/Crypto/WalletButtons.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/compat/styleToTheme.mjs +15 -14
- package/dist/esm-dev/packages/web/src/ui/compat/styleToTheme.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/PresentationConfig.mjs +9 -3
- package/dist/esm-dev/packages/web/src/ui/components/PresentationConfig.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/atoms/Button.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/atoms/Typography.module.css.mjs +2 -2
- package/dist/esm-dev/packages/web/src/ui/components/molecules/EmailInput.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/molecules/EmailInput.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/molecules/Input.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/components/molecules/Input.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/B2BIdentityProvider.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/B2BIdentityProvider.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/Stytch.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/Stytch.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/StytchB2BContext.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2b/StytchB2BContext.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/IdentityProvider.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/IdentityProvider.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchContext.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchContext.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchLogin.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchLogin.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchPasskeyRegistration.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchPasskeyRegistration.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchPasswordReset.mjs +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/b2c/StytchPasswordReset.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/ui/react/utils/errors.mjs +8 -4
- package/dist/esm-dev/packages/web/src/ui/react/utils/errors.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/utils/crypto.mjs +19 -14
- package/dist/esm-dev/packages/web/src/utils/crypto.mjs.map +1 -1
- package/dist/esm-dev/packages/web/src/utils/oauthProviderType.mjs +1 -1
- package/dist/esm-dev/packages/web/src/utils/oauthProviderType.mjs.map +1 -1
- package/dist/types/{PresentationConfig-Bqzf8zr3.d.ts → PresentationConfig-B2jX85oV.d.ts} +13 -2
- package/dist/types/{StytchB2BClient-CsY7ZNKh.d.ts → StytchB2BClient-D16e_lp1.d.ts} +2 -2
- package/dist/types/{StytchClient-DZRM_fM4.d.ts → StytchClient-BwQdJzdj.d.ts} +2 -2
- package/dist/types/adminPortal/index.d.ts +5 -5
- package/dist/types/b2b/index.d.ts +27 -19
- package/dist/types/b2b/index.headless.d.ts +5 -5
- package/dist/types/compat.d.ts +2 -2
- package/dist/types/{createAuthUrlHandler-BZoD2LDF.d.ts → createAuthUrlHandler-R1kNNQD_.d.ts} +2 -2
- package/dist/types/{idpHelpers-CD5sSDzA.d.ts → idpHelpers-BQP76WgZ.d.ts} +1 -1
- package/dist/types/index.d.ts +36 -16
- package/dist/types/index.headless.d.ts +5 -5
- package/dist/types/{shadcn-4-5byj93.d.ts → shadcn-CGdmyIUF.d.ts} +9 -6
- package/dist/types/{ui-DXrQ-gA8.d.ts → ui-B7IvSGQf.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/cjs/index-Ni_dyEsz.js.map +0 -1
- package/dist/cjs/shadcn-B8TEzQMT.js.map +0 -1
- package/dist/cjs-dev/StytchSSRProxy-CxXsyme4.js.map +0 -1
- package/dist/cjs-dev/idpHelpers-BVMUYvt1.js.map +0 -1
- package/dist/cjs-dev/index-DdK3Jt4u.js.map +0 -1
- package/dist/cjs-dev/shadcn-C9ClUju1.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StytchB2BContext.mjs","sources":["../../../../../../../../../web/src/ui/react/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n Member,\n MemberSession,\n Organization,\n PermissionsMap,\n StytchProjectConfigurationInput,\n} from '@stytch/core/public';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport { isStytchSSRProxy } from '../bindings/StytchSSRProxy';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport { StytchB2BClient } from '../../../b2b/StytchB2BClient';\n\n// There's no user facing strings in this file\n/* eslint-disable lingui/no-unlocalized-strings */\n\ntype StytchB2BContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchB2BClient<TProjectConfiguration>;\n };\n\ntype SWRMemberUninitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberInitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: Member | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMember<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberInitialized\n : SWRMemberInitialized | SWRMemberUninitialized;\n\nconst initialMember: SWRMember = {\n member: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRMemberSessionUninitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberSessionInitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: MemberSession | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMemberSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberSessionInitialized\n : SWRMemberSessionInitialized | SWRMemberSessionUninitialized;\n\nconst initialMemberSession: SWRMemberSession = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWROrganizationUninitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWROrganizationInitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: Organization | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWROrganization<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWROrganizationInitialized\n : SWROrganizationInitialized | SWROrganizationUninitialized;\n\nconst initialOrganization: SWROrganization = {\n organization: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchB2BContext = createContext<StytchB2BContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchMemberContext = createContext<SWRMember>(initialMember);\nconst StytchMemberSessionContext = createContext<SWRMemberSession>(initialMemberSession);\nconst StytchOrganizationContext = createContext<SWROrganization>(initialOrganization);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchB2BContext).isMounted;\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = <TAssumeHydrated extends boolean = false>(): SWRMember<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMember', 'StytchB2BProvider'));\n return useContext(StytchMemberContext) as SWRMember<TAssumeHydrated>;\n};\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = <\n TAssumeHydrated extends boolean = false,\n>(): SWRMemberSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMemberSession', 'StytchB2BProvider'));\n return useContext(StytchMemberSessionContext) as SWRMemberSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = <TAssumeHydrated extends boolean = false>(): SWROrganization<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchOrganization', 'StytchB2BProvider'));\n return useContext(StytchOrganizationContext) as SWROrganization<TAssumeHydrated>;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, session?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\n/**\n * Returns the Stytch B2B client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytchB2BClient();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytchB2BClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchB2BClient<TProjectConfiguration> => {\n const ctx = useContext(StytchB2BContext);\n invariant(ctx.isMounted, noProviderError('useStytchB2BClient', 'StytchB2BProvider'));\n return ctx.client as StytchB2BClient<TProjectConfiguration>;\n};\n\nexport const withStytchB2BClient = <T extends object, TProjectConfiguration extends StytchProjectConfigurationInput>(\n Component: ComponentType<T & { stytch: StytchB2BClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchB2BClient', 'StytchB2BProvider'));\n return <Component {...props} stytch={useStytchB2BClient()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchMember = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMember', 'StytchB2BProvider'));\n const { member, isInitialized, fromCache } = useStytchMember<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMember={member}\n stytchMemberIsInitialized={isInitialized}\n stytchMemberIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchMember(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchMemberSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMemberSession', 'StytchB2BProvider'));\n const { session, isInitialized, fromCache } = useStytchMemberSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMemberSession={session}\n stytchMemberSessionIsInitialized={isInitialized}\n stytchMemberSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchMemberSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport const withStytchOrganization = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchOrganization: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchOrganization', 'StytchB2BProvider'));\n const { organization, isInitialized, fromCache } = useStytchOrganization<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchOrganization={organization}\n stytchOrganizationIsInitialized={isInitialized}\n stytchOrganizationIsFromCache={fromCache}\n />\n );\n };\n WithStytchOrganization.displayName = `withStytchOrganization(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchOrganization;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in member.\n * Evaluates all permissions granted to the logged-in member.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.\n * Each boolean will be `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n useEffect(() => {\n client.rbac\n .allPermissions<Permissions>()\n .then((permissions) => setPermissions({ loaded: true, value: permissions }));\n }, [client, session?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchB2BClient} or {@link createStytchB2BClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.');\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchB2BProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n member: SWRMember<TAlwaysInitialized>;\n session: SWRMemberSession<TAlwaysInitialized>;\n organization: SWROrganization<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n member: { ...stytch.self.getInfo(), isInitialized: true },\n session: { ...stytch.session.getInfo(), isInitialized: true },\n organization: { ...stytch.organization.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n member: initialMember,\n session: initialMemberSession,\n organization: initialOrganization,\n } satisfies ClientState<false>;\n };\n\n const [{ member, session, organization }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchB2BContext.Provider value={ctx}>\n <StytchOrganizationContext.Provider value={organization}>\n <StytchMemberContext.Provider value={member}>\n <StytchMemberSessionContext.Provider value={session}>{children}</StytchMemberSessionContext.Provider>\n </StytchMemberContext.Provider>\n </StytchOrganizationContext.Provider>\n </StytchB2BContext.Provider>\n );\n};\n"],"names":["initialMember","member","fromCache","isInitialized","initialMemberSession","session","initialOrganization","organization","StytchB2BContext","createContext","isMounted","StytchMemberContext","StytchMemberSessionContext","StytchOrganizationContext","useIsMounted__INTERNAL","useContext","useStytchMember","invariant","noProviderError","useStytchMemberSession","useStytchOrganization","useStytchIsAuthorized","resourceId","action","client","useStytchB2BClient","isAuthorized","setIsAuthorized","useAsyncState","useEffect","isStytchSSRProxy","rbac","isAuthorizedSync","then","roles","ctx","withStytchB2BClient","Component","WithStytch","props","React","stytch","displayName","name","withStytchMember","WithStytchUser","stytchMember","stytchMemberIsInitialized","stytchMemberIsFromCache","withStytchMemberSession","WithStytchSession","stytchMemberSession","stytchMemberSessionIsInitialized","stytchMemberSessionIsFromCache","withStytchOrganization","WithStytchOrganization","stytchOrganization","stytchOrganizationIsInitialized","stytchOrganizationIsFromCache","withStytchPermissions","WithStytchPermissions","permissions","setPermissions","loaded","value","allPermissions","stytchPermissions","StytchB2BProvider","children","assumeHydrated","window","useMemo","getHydratedState","useCallback","self","getInfo","getInitialState","setClientState","assumeHydratedRef","useRef","updateState","oldState","mergeWithStableProps","current","onStateChange","Provider"],"mappings":";;;;;;;AAuEA,MAAMA,aAAAA,GAA2B;IAC/BC,MAAAA,EAAQ,IAAA;IACRC,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMC,oBAAAA,GAAyC;IAC7CC,OAAAA,EAAS,IAAA;IACTH,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMG,mBAAAA,GAAuC;IAC3CC,YAAAA,EAAc,IAAA;IACdL,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMK,iCAAmBC,aAAAA,CAAiE;IAAEC,SAAAA,EAAW;AAAM,CAAA,CAAA;AAC7G,MAAMC,oCAAsBF,aAAAA,CAAyBT,aAAAA,CAAAA;AACrD,MAAMY,2CAA6BH,aAAAA,CAAgCL,oBAAAA,CAAAA;AACnE,MAAMS,0CAA4BJ,aAAAA,CAA+BH,mBAAAA,CAAAA;MAEpDQ,sBAAAA,GAAyB,IAAeC,UAAAA,CAAWP,gBAAAA,CAAAA,CAAkBE;AAElF;;;;;;;;;;;UAYaM,eAAAA,GAAkB,IAAA;IAC7BC,SAAAA,CAAUH,sBAAAA,EAAAA,EAA0BI,gBAAgB,iBAAA,EAAmB,mBAAA,CAAA,CAAA;AACvE,IAAA,OAAOH,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AAAA;AAAO,KAAA,CAAA;IAE7C,qBACED,cAAA,CAAA,aAAA,CAAChC,iBAAiB6E,QAAQ,EAAA;QAACrB,KAAAA,EAAO7B;AAChC,KAAA,gBAAAK,cAAA,CAAA,aAAA,CAAC3B,0BAA0BwE,QAAQ,EAAA;QAACrB,KAAAA,EAAOzD;AACzC,KAAA,gBAAAiC,cAAA,CAAA,aAAA,CAAC7B,oBAAoB0E,QAAQ,EAAA;QAACrB,KAAAA,EAAO/D;AACnC,KAAA,gBAAAuC,cAAA,CAAA,aAAA,CAAC5B,2BAA2ByE,QAAQ,EAAA;QAACrB,KAAAA,EAAO3D;AAAU+D,KAAAA,EAAAA,QAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAKhE;;;;"}
|
|
1
|
+
{"version":3,"file":"StytchB2BContext.mjs","sources":["../../../../../../../../../web/src/ui/react/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n Member,\n MemberSession,\n Organization,\n PermissionsMap,\n StytchProjectConfigurationInput,\n} from '@stytch/core/public';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport { isStytchSSRProxy } from '../bindings/StytchSSRProxy';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport { StytchB2BClient } from '../../../b2b/StytchB2BClient';\n\n// There's no user facing strings in this file\n/* eslint-disable lingui/no-unlocalized-strings */\n\ntype StytchB2BContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchB2BClient<TProjectConfiguration>;\n };\n\ntype SWRMemberUninitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberInitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: Member | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMember<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberInitialized\n : SWRMemberInitialized | SWRMemberUninitialized;\n\nconst initialMember: SWRMember = {\n member: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRMemberSessionUninitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberSessionInitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: MemberSession | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMemberSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberSessionInitialized\n : SWRMemberSessionInitialized | SWRMemberSessionUninitialized;\n\nconst initialMemberSession: SWRMemberSession = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWROrganizationUninitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWROrganizationInitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: Organization | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWROrganization<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWROrganizationInitialized\n : SWROrganizationInitialized | SWROrganizationUninitialized;\n\nconst initialOrganization: SWROrganization = {\n organization: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchB2BContext = createContext<StytchB2BContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchMemberContext = createContext<SWRMember>(initialMember);\nconst StytchMemberSessionContext = createContext<SWRMemberSession>(initialMemberSession);\nconst StytchOrganizationContext = createContext<SWROrganization>(initialOrganization);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchB2BContext).isMounted;\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = <TAssumeHydrated extends boolean = false>(): SWRMember<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMember', 'StytchB2BProvider'));\n return useContext(StytchMemberContext) as SWRMember<TAssumeHydrated>;\n};\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = <\n TAssumeHydrated extends boolean = false,\n>(): SWRMemberSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMemberSession', 'StytchB2BProvider'));\n return useContext(StytchMemberSessionContext) as SWRMemberSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = <TAssumeHydrated extends boolean = false>(): SWROrganization<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchOrganization', 'StytchB2BProvider'));\n return useContext(StytchOrganizationContext) as SWROrganization<TAssumeHydrated>;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, session?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\n/**\n * Returns the Stytch B2B client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytchB2BClient();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytchB2BClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchB2BClient<TProjectConfiguration> => {\n const ctx = useContext(StytchB2BContext);\n invariant(ctx.isMounted, noProviderError('useStytchB2BClient', 'StytchB2BProvider'));\n return ctx.client as StytchB2BClient<TProjectConfiguration>;\n};\n\nexport const withStytchB2BClient = <T extends object, TProjectConfiguration extends StytchProjectConfigurationInput>(\n Component: ComponentType<T & { stytch: StytchB2BClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchB2BClient', 'StytchB2BProvider'));\n return <Component {...props} stytch={useStytchB2BClient()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchMember = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMember', 'StytchB2BProvider'));\n const { member, isInitialized, fromCache } = useStytchMember<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMember={member}\n stytchMemberIsInitialized={isInitialized}\n stytchMemberIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchMember(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchMemberSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMemberSession', 'StytchB2BProvider'));\n const { session, isInitialized, fromCache } = useStytchMemberSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMemberSession={session}\n stytchMemberSessionIsInitialized={isInitialized}\n stytchMemberSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchMemberSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport const withStytchOrganization = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchOrganization: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchOrganization', 'StytchB2BProvider'));\n const { organization, isInitialized, fromCache } = useStytchOrganization<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchOrganization={organization}\n stytchOrganizationIsInitialized={isInitialized}\n stytchOrganizationIsFromCache={fromCache}\n />\n );\n };\n WithStytchOrganization.displayName = `withStytchOrganization(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchOrganization;\n};\n\ntype PermissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in member.\n * Evaluates all permissions granted to the logged-in member.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.\n * Each boolean will be `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [permissions, setPermissions] = useAsyncState<PermissionsLoaded<Permissions>>({ loaded: false, value: null });\n useEffect(() => {\n client.rbac\n .allPermissions<Permissions>()\n .then((permissions) => setPermissions({ loaded: true, value: permissions }));\n }, [client, session?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchB2BClient} or {@link createStytchB2BClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.');\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchB2BProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n member: SWRMember<TAlwaysInitialized>;\n session: SWRMemberSession<TAlwaysInitialized>;\n organization: SWROrganization<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n member: { ...stytch.self.getInfo(), isInitialized: true },\n session: { ...stytch.session.getInfo(), isInitialized: true },\n organization: { ...stytch.organization.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n member: initialMember,\n session: initialMemberSession,\n organization: initialOrganization,\n } satisfies ClientState<false>;\n };\n\n const [{ member, session, organization }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchB2BContext.Provider value={ctx}>\n <StytchOrganizationContext.Provider value={organization}>\n <StytchMemberContext.Provider value={member}>\n <StytchMemberSessionContext.Provider value={session}>{children}</StytchMemberSessionContext.Provider>\n </StytchMemberContext.Provider>\n </StytchOrganizationContext.Provider>\n </StytchB2BContext.Provider>\n );\n};\n"],"names":["initialMember","member","fromCache","isInitialized","initialMemberSession","session","initialOrganization","organization","StytchB2BContext","createContext","isMounted","StytchMemberContext","StytchMemberSessionContext","StytchOrganizationContext","useIsMounted__INTERNAL","useContext","useStytchMember","invariant","noProviderError","useStytchMemberSession","useStytchOrganization","useStytchIsAuthorized","resourceId","action","client","useStytchB2BClient","isAuthorized","setIsAuthorized","useAsyncState","useEffect","isStytchSSRProxy","rbac","isAuthorizedSync","then","roles","ctx","withStytchB2BClient","Component","WithStytch","props","React","stytch","displayName","name","withStytchMember","WithStytchUser","stytchMember","stytchMemberIsInitialized","stytchMemberIsFromCache","withStytchMemberSession","WithStytchSession","stytchMemberSession","stytchMemberSessionIsInitialized","stytchMemberSessionIsFromCache","withStytchOrganization","WithStytchOrganization","stytchOrganization","stytchOrganizationIsInitialized","stytchOrganizationIsFromCache","withStytchPermissions","WithStytchPermissions","permissions","setPermissions","loaded","value","allPermissions","stytchPermissions","StytchB2BProvider","children","assumeHydrated","window","useMemo","getHydratedState","useCallback","self","getInfo","getInitialState","setClientState","assumeHydratedRef","useRef","updateState","oldState","mergeWithStableProps","current","onStateChange","Provider"],"mappings":";;;;;;;AAuEA,MAAMA,aAAAA,GAA2B;IAC/BC,MAAAA,EAAQ,IAAA;IACRC,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMC,oBAAAA,GAAyC;IAC7CC,OAAAA,EAAS,IAAA;IACTH,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMG,mBAAAA,GAAuC;IAC3CC,YAAAA,EAAc,IAAA;IACdL,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMK,iCAAmBC,aAAAA,CAAiE;IAAEC,SAAAA,EAAW;AAAM,CAAA,CAAA;AAC7G,MAAMC,oCAAsBF,aAAAA,CAAyBT,aAAAA,CAAAA;AACrD,MAAMY,2CAA6BH,aAAAA,CAAgCL,oBAAAA,CAAAA;AACnE,MAAMS,0CAA4BJ,aAAAA,CAA+BH,mBAAAA,CAAAA;MAEpDQ,sBAAAA,GAAyB,IAAeC,UAAAA,CAAWP,gBAAAA,CAAAA,CAAkBE;AAElF;;;;;;;;;;;UAYaM,eAAAA,GAAkB,IAAA;IAC7BC,SAAAA,CAAUH,sBAAAA,EAAAA,EAA0BI,gBAAgB,iBAAA,EAAmB,mBAAA,CAAA,CAAA;AACvE,IAAA,OAAOH,UAAAA,CAAWJ,mBAAAA,CAAAA;AACpB;AAEA;;;;;;;;;;;;;;;UAgBaQ,sBAAAA,GAAyB,IAAA;IAGpCF,SAAAA,CAAUH,sBAAAA,EAAAA,EAA0BI,gBAAgB,wBAAA,EAA0B,mBAAA,CAAA,CAAA;AAC9E,IAAA,OAAOH,UAAAA,CAAWH,0BAAAA,CAAAA;AACpB;AAEA;;;;;;;;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oBAAoB0E,QAAQ,EAAA;QAACrB,KAAAA,EAAO/D;AACnC,KAAA,gBAAAuC,cAAA,CAAA,aAAA,CAAC5B,2BAA2ByE,QAAQ,EAAA;QAACrB,KAAAA,EAAO3D;AAAU+D,KAAAA,EAAAA,QAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAKhE;;;;"}
|
|
@@ -20,7 +20,7 @@ import { createB2CComponent } from '../bindings/createB2CComponent.mjs';
|
|
|
20
20
|
* onEvent: (event) => console.log(event)
|
|
21
21
|
* }}
|
|
22
22
|
* />
|
|
23
|
-
*/ const IdentityProvider = createB2CComponent('IdentityProvider', IDPContainer);
|
|
23
|
+
*/ const IdentityProvider = /* @__PURE__ */ createB2CComponent('IdentityProvider', IDPContainer);
|
|
24
24
|
|
|
25
25
|
export { IdentityProvider };
|
|
26
26
|
//# sourceMappingURL=IdentityProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/IdentityProvider.tsx"],"sourcesContent":["import { IDPContainer } from '../../b2c/IDPContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\nimport { StytchProps } from './StytchLogin';\nimport { AuthTokenParams, IDPConsentManifestGenerator } from '../../../types';\n\nexport type IdentityProviderProps = Omit<StytchProps, 'config'> & {\n /**\n * Optional {@link IDPConsentManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: IDPConsentManifestGenerator;\n /**\n * Optional {@link AuthTokenParams} to provide a trusted auth token to provide for attestation prior to running OAuth flow.\n */\n authTokenParams?: AuthTokenParams;\n};\n\n/**\n * The Stytch IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <IdentityProvider\n * presentation={{\n * theme: { primary: '#ff00f7' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const IdentityProvider = createB2CComponent('IdentityProvider', IDPContainer);\n"],"names":["IdentityProvider","createB2CComponent","IDPContainer"],"mappings":";;;AAgBA;;;;;;;;;;;;;;;;;;;AAmBC,IACM,MAAMA,gBAAAA,
|
|
1
|
+
{"version":3,"file":"IdentityProvider.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/IdentityProvider.tsx"],"sourcesContent":["import { IDPContainer } from '../../b2c/IDPContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\nimport { StytchProps } from './StytchLogin';\nimport { AuthTokenParams, IDPConsentManifestGenerator } from '../../../types';\n\nexport type IdentityProviderProps = Omit<StytchProps, 'config'> & {\n /**\n * Optional {@link IDPConsentManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: IDPConsentManifestGenerator;\n /**\n * Optional {@link AuthTokenParams} to provide a trusted auth token to provide for attestation prior to running OAuth flow.\n */\n authTokenParams?: AuthTokenParams;\n};\n\n/**\n * The Stytch IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <IdentityProvider\n * presentation={{\n * theme: { primary: '#ff00f7' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const IdentityProvider = /* @__PURE__ */ createB2CComponent('IdentityProvider', IDPContainer);\n"],"names":["IdentityProvider","createB2CComponent","IDPContainer"],"mappings":";;;AAgBA;;;;;;;;;;;;;;;;;;;AAmBC,IACM,MAAMA,gBAAAA,mBAAmCC,kBAAAA,CAAmB,oBAAoBC,YAAAA;;;;"}
|
|
@@ -116,7 +116,7 @@ const withStytchSession = (Component)=>{
|
|
|
116
116
|
*
|
|
117
117
|
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
118
118
|
* @example
|
|
119
|
-
* const { isAuthorized } = useStytchIsAuthorized
|
|
119
|
+
* const { isAuthorized } = useStytchIsAuthorized('documents', 'edit');
|
|
120
120
|
* return <button disabled={!isAuthorized}>Edit</button>
|
|
121
121
|
*/ const useStytchIsAuthorized = (resourceId, action)=>{
|
|
122
122
|
invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StytchContext.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchContext.tsx"],"sourcesContent":["'use client';\n\nimport React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport { PermissionsMap, Session, StytchProjectConfigurationInput, User } from '@stytch/core/public';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError, providerMustBeUniqueError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport { isStytchSSRProxy } from '../bindings/StytchSSRProxy';\nimport { StytchClient } from '../../../StytchClient';\n\n// There's no user facing strings in this file\n/* eslint-disable lingui/no-unlocalized-strings */\n\ntype StytchContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchClient<TProjectConfiguration>;\n };\n\ntype SWRUserUninitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRUserInitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: User | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRUser<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRUserInitialized\n : SWRUserInitialized | SWRUserUninitialized;\n\nconst initialUser: SWRUserUninitialized = {\n user: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRSessionUninitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRSessionInitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: Session | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRSessionInitialized\n : SWRSessionInitialized | SWRSessionUninitialized;\n\nconst initialSession: SWRSessionUninitialized = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchContext = createContext<StytchContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchUserContext = createContext<SWRUser>(initialUser);\nconst StytchSessionContext = createContext<SWRSession>(initialSession);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchContext).isMounted;\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = <TAssumeHydrated extends boolean = false>(): SWRUser<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext) as SWRUser<TAssumeHydrated>;\n};\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = <TAssumeHydrated extends boolean = false>(): SWRSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext) as SWRSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the Stytch client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytch();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytch = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchClient<TProjectConfiguration> => {\n const ctx = useContext(StytchContext);\n invariant(ctx.isMounted, noProviderError('useStytch'));\n return ctx.client as StytchClient<TProjectConfiguration>;\n};\n\nexport const withStytch = <\n T extends object,\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n Component: ComponentType<T & { stytch: StytchClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchUser = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n const { user, isInitialized, fromCache } = useStytchUser<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchUser={user}\n stytchUserIsInitialized={isInitialized}\n stytchUserIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n const { session, isInitialized, fromCache } = useStytchSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchSession={session}\n stytchSessionIsInitialized={isInitialized}\n stytchSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in user is allowed to perform the specified action on the specified resource.\n * Returns `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, user?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in user.\n * Evaluates all permissions granted to the logged-in user.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.\n * Each boolean will be `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n\n useEffect(() => {\n client.rbac.allPermissions<Permissions>().then((permissions) => {\n setPermissions({ loaded: true, value: permissions });\n });\n }, [client, user?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchProviderProps<TProjectConfiguration>) => {\n invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n session: SWRSession<TAlwaysInitialized>;\n user: SWRUser<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n session: { ...stytch.session.getInfo(), isInitialized: true },\n user: { ...stytch.user.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n session: initialSession,\n user: initialUser,\n } satisfies ClientState<false>;\n };\n\n const [{ user, session }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchContext.Provider value={ctx}>\n <StytchUserContext.Provider value={user}>\n <StytchSessionContext.Provider value={session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n );\n};\n"],"names":["initialUser","user","fromCache","isInitialized","initialSession","session","StytchContext","createContext","isMounted","StytchUserContext","StytchSessionContext","useIsMounted__INTERNAL","useContext","useStytchUser","invariant","noProviderError","useStytchSession","useStytch","ctx","client","withStytch","Component","WithStytch","props","React","stytch","displayName","name","withStytchUser","WithStytchUser","stytchUser","stytchUserIsInitialized","stytchUserIsFromCache","withStytchSession","WithStytchSession","stytchSession","stytchSessionIsInitialized","stytchSessionIsFromCache","useStytchIsAuthorized","resourceId","action","isAuthorized","setIsAuthorized","useAsyncState","useEffect","isStytchSSRProxy","rbac","isAuthorizedSync","then","roles","withStytchPermissions","WithStytchPermissions","permissions","setPermissions","loaded","value","allPermissions","stytchPermissions","StytchProvider","children","assumeHydrated","providerMustBeUniqueError","window","useMemo","getHydratedState","useCallback","getInfo","getInitialState","setClientState","assumeHydratedRef","useRef","updateState","oldState","mergeWithStableProps","current","onStateChange","Provider"],"mappings":";;;;;;;AAkEA,MAAMA,WAAAA,GAAoC;IACxCC,IAAAA,EAAM,IAAA;IACNC,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMC,cAAAA,GAA0C;IAC9CC,OAAAA,EAAS,IAAA;IACTH,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMG,8BAAgBC,aAAAA,CAA8D;IAAEC,SAAAA,EAAW;AAAM,CAAA,CAAA;AACvG,MAAMC,kCAAoBF,aAAAA,CAAuBP,WAAAA,CAAAA;AACjD,MAAMU,qCAAuBH,aAAAA,CAA0BH,cAAAA,CAAAA;MAE1CO,sBAAAA,GAAyB,IAAeC,UAAAA,CAAWN,aAAAA,CAAAA,CAAeE;AAE/E;;;;;;;;;;;UAYaK,aAAAA,GAAgB,IAAA;AAC3BC,IAAAA,SAAAA,CAAUH,0BAA0BI,eAAAA,CAAgB,eAAA,CAAA,CAAA;AACpD,IAAA,OAAOH,UAAAA,CAAWH,iBAAAA,CAAAA;AACpB;AAEA;;;;;;;;;;;;;;;UAgBaO,gBAAAA,GAAmB,IAAA;AAC9BF,IAAAA,SAAAA,CAAUH,0BAA0BI,eAAAA,CAAgB,kBAAA,CAAA,CAAA;AACpD,IAAA,OAAOH,UAAAA,CAAWF,oBAAAA,CAAAA;AACpB;AAEA;;;;;;;;UASaO,SAAAA,GAAY,IAAA;AAGvB,IAAA,MAAMC,MAAMN,UAA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gBAAAM,cAAA,CAAA,aAAA,CAACf,kBAAkBmE,QAAQ,EAAA;QAACrB,KAAAA,EAAOtD;AACjC,KAAA,gBAAAuB,cAAA,CAAA,aAAA,CAACd,qBAAqBkE,QAAQ,EAAA;QAACrB,KAAAA,EAAOlD;AAAUsD,KAAAA,EAAAA,QAAAA,CAAAA,CAAAA,CAAAA;AAIxD;;;;"}
|
|
1
|
+
{"version":3,"file":"StytchContext.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchContext.tsx"],"sourcesContent":["'use client';\n\nimport React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport { PermissionsMap, Session, StytchProjectConfigurationInput, User } from '@stytch/core/public';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError, providerMustBeUniqueError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport { isStytchSSRProxy } from '../bindings/StytchSSRProxy';\nimport { StytchClient } from '../../../StytchClient';\n\n// There's no user facing strings in this file\n/* eslint-disable lingui/no-unlocalized-strings */\n\ntype StytchContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchClient<TProjectConfiguration>;\n };\n\ntype SWRUserUninitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRUserInitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: User | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRUser<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRUserInitialized\n : SWRUserInitialized | SWRUserUninitialized;\n\nconst initialUser: SWRUserUninitialized = {\n user: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRSessionUninitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRSessionInitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: Session | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRSessionInitialized\n : SWRSessionInitialized | SWRSessionUninitialized;\n\nconst initialSession: SWRSessionUninitialized = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchContext = createContext<StytchContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchUserContext = createContext<SWRUser>(initialUser);\nconst StytchSessionContext = createContext<SWRSession>(initialSession);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchContext).isMounted;\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = <TAssumeHydrated extends boolean = false>(): SWRUser<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext) as SWRUser<TAssumeHydrated>;\n};\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = <TAssumeHydrated extends boolean = false>(): SWRSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext) as SWRSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the Stytch client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytch();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytch = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchClient<TProjectConfiguration> => {\n const ctx = useContext(StytchContext);\n invariant(ctx.isMounted, noProviderError('useStytch'));\n return ctx.client as StytchClient<TProjectConfiguration>;\n};\n\nexport const withStytch = <\n T extends object,\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n Component: ComponentType<T & { stytch: StytchClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchUser = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n const { user, isInitialized, fromCache } = useStytchUser<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchUser={user}\n stytchUserIsInitialized={isInitialized}\n stytchUserIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n const { session, isInitialized, fromCache } = useStytchSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchSession={session}\n stytchSessionIsInitialized={isInitialized}\n stytchSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in user is allowed to perform the specified action on the specified resource.\n * Returns `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, user?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in user.\n * Evaluates all permissions granted to the logged-in user.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.\n * Each boolean will be `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n\n useEffect(() => {\n client.rbac.allPermissions<Permissions>().then((permissions) => {\n setPermissions({ loaded: true, value: permissions });\n });\n }, [client, user?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchProviderProps<TProjectConfiguration>) => {\n invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n session: SWRSession<TAlwaysInitialized>;\n user: SWRUser<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n session: { ...stytch.session.getInfo(), isInitialized: true },\n user: { ...stytch.user.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n session: initialSession,\n user: initialUser,\n } satisfies ClientState<false>;\n };\n\n const [{ user, session }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchContext.Provider value={ctx}>\n <StytchUserContext.Provider value={user}>\n <StytchSessionContext.Provider value={session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n );\n};\n"],"names":["initialUser","user","fromCache","isInitialized","initialSession","session","StytchContext","createContext","isMounted","StytchUserContext","StytchSessionContext","useIsMounted__INTERNAL","useContext","useStytchUser","invariant","noProviderError","useStytchSession","useStytch","ctx","client","withStytch","Component","WithStytch","props","React","stytch","displayName","name","withStytchUser","WithStytchUser","stytchUser","stytchUserIsInitialized","stytchUserIsFromCache","withStytchSession","WithStytchSession","stytchSession","stytchSessionIsInitialized","stytchSessionIsFromCache","useStytchIsAuthorized","resourceId","action","isAuthorized","setIsAuthorized","useAsyncState","useEffect","isStytchSSRProxy","rbac","isAuthorizedSync","then","roles","withStytchPermissions","WithStytchPermissions","permissions","setPermissions","loaded","value","allPermissions","stytchPermissions","StytchProvider","children","assumeHydrated","providerMustBeUniqueError","window","useMemo","getHydratedState","useCallback","getInfo","getInitialState","setClientState","assumeHydratedRef","useRef","updateState","oldState","mergeWithStableProps","current","onStateChange","Provider"],"mappings":";;;;;;;AAkEA,MAAMA,WAAAA,GAAoC;IACxCC,IAAAA,EAAM,IAAA;IACNC,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAoCA,MAAMC,cAAAA,GAA0C;IAC9CC,OAAAA,EAAS,IAAA;IACTH,SAAAA,EAAW,KAAA;IACXC,aAAAA,EAAe;AACjB,CAAA;AAEA,MAAMG,8BAAgBC,aAAAA,CAA8D;IAAEC,SAAAA,EAAW;AAAM,CAAA,CAAA;AACvG,MAAMC,kCAAoBF,aAAAA,CAAuBP,WAAAA,CAAAA;AACjD,MAAMU,qCAAuBH,aAAAA,CAA0BH,cAAAA,CAAAA;MAE1CO,sBAAAA,GAAyB,IAAeC,UAAAA,CAAWN,aAAAA,CAAAA,CAAeE;AAE/E;;;;;;;;;;;UAYaK,aAAAA,GAAgB,IAAA;AAC3BC,IAAAA,SAAAA,CAAUH,0BAA0BI,eAAAA,CAAgB,eAAA,CAAA,CAAA;AACpD,IAAA,OAAOH,UAAAA,CAAWH,iBAAAA,CAAAA;AACpB;AAEA;;;;;;;;;;;;;;;UAgBaO,gBAAAA,GAAmB,IAAA;AAC9BF,IAAAA,SAAAA,CAAUH,0BAA0BI,eAAAA,CAAgB,kBAAA,CAAA,CAAA;AACpD,IAAA,OAAOH,UAAAA,CAAWF,oBAAAA,CAAAA;AACpB;AAEA;;;;;;;;UASaO,SAAAA,GAAY,IAAA;AAGvB,IAAA,MAAMC,MAAMN,UAAAA,CAAWN,aAAAA,CAAAA;IACvBQ,SAAAA,CAAUI,GAA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AAA;QAACrB,KAAAA,EAAOtD;AACjC,KAAA,gBAAAuB,cAAA,CAAA,aAAA,CAACd,qBAAqBkE,QAAQ,EAAA;QAACrB,KAAAA,EAAOlD;AAAUsD,KAAAA,EAAAA,QAAAA,CAAAA,CAAAA,CAAAA;AAIxD;;;;"}
|
|
@@ -28,7 +28,7 @@ import { createB2CComponent } from '../bindings/createB2CComponent.mjs';
|
|
|
28
28
|
* onEvent: (event) => console.log(event)
|
|
29
29
|
* }}
|
|
30
30
|
* />
|
|
31
|
-
*/ const StytchLogin = createB2CComponent('StytchLogin', AppContainer);
|
|
31
|
+
*/ const StytchLogin = /* @__PURE__ */ createB2CComponent('StytchLogin', AppContainer);
|
|
32
32
|
|
|
33
33
|
export { StytchLogin };
|
|
34
34
|
//# sourceMappingURL=StytchLogin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StytchLogin.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchLogin.tsx"],"sourcesContent":["import { Callbacks, StringsOptions, StytchProjectConfigurationInput } from '@stytch/core/public';\nimport { AppContainer } from '../../b2c/AppContainer';\nimport { PresentationConfig, StytchLoginConfig } from '../../../types';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\n\nexport interface StytchProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n * @example\n * {\n * products: [Products.crypto, Products.otp]\n * }\n *\n * @example\n * {\n * products: [Products.emailMagicLinks]\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * }\n * }\n *\n * @example\n * {\n * products: [Products.oauth]\n * oauthOptions: {\n * providers: [\n * { type: 'google', one_tap: true, position: 'embedded' },\n * { type: 'microsoft' },\n * { type: 'apple' },\n * { type: 'facebook' },\n * ],\n * }\n * }\n */\n config: StytchLoginConfig;\n /**\n * An optional {@link PresentationConfig} to customize the UI presentation.\n */\n presentation?: PresentationConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch login screen error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.CryptoWalletAuthenticate) {\n * console.log('Logged in with crypto wallet', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n}\n\n/**\n * The Stytch Login Screen component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchLogin\n * config={{\n * products: [Products.emailMagicLinks, Products.oauth],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * presentation={{\n * theme: { primary: '#0577CA' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchLogin = createB2CComponent('StytchLogin', AppContainer);\n"],"names":["StytchLogin","createB2CComponent","AppContainer"],"mappings":";;;AAiEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BC,IACM,MAAMA,WAAAA,
|
|
1
|
+
{"version":3,"file":"StytchLogin.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchLogin.tsx"],"sourcesContent":["import { Callbacks, StringsOptions, StytchProjectConfigurationInput } from '@stytch/core/public';\nimport { AppContainer } from '../../b2c/AppContainer';\nimport { PresentationConfig, StytchLoginConfig } from '../../../types';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\n\nexport interface StytchProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n * @example\n * {\n * products: [Products.crypto, Products.otp]\n * }\n *\n * @example\n * {\n * products: [Products.emailMagicLinks]\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * }\n * }\n *\n * @example\n * {\n * products: [Products.oauth]\n * oauthOptions: {\n * providers: [\n * { type: 'google', one_tap: true, position: 'embedded' },\n * { type: 'microsoft' },\n * { type: 'apple' },\n * { type: 'facebook' },\n * ],\n * }\n * }\n */\n config: StytchLoginConfig;\n /**\n * An optional {@link PresentationConfig} to customize the UI presentation.\n */\n presentation?: PresentationConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch login screen error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.CryptoWalletAuthenticate) {\n * console.log('Logged in with crypto wallet', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n}\n\n/**\n * The Stytch Login Screen component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchLogin\n * config={{\n * products: [Products.emailMagicLinks, Products.oauth],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * presentation={{\n * theme: { primary: '#0577CA' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchLogin = /* @__PURE__ */ createB2CComponent('StytchLogin', AppContainer);\n"],"names":["StytchLogin","createB2CComponent","AppContainer"],"mappings":";;;AAiEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BC,IACM,MAAMA,WAAAA,mBAA8BC,kBAAAA,CAAmB,eAAeC,YAAAA;;;;"}
|
|
@@ -18,7 +18,7 @@ import { createB2CComponent } from '../bindings/createB2CComponent.mjs';
|
|
|
18
18
|
* onEvent: (event) => console.log(event)
|
|
19
19
|
* }}
|
|
20
20
|
* />
|
|
21
|
-
*/ const StytchPasskeyRegistration = createB2CComponent('StytchPasskeyRegistration', PasskeyRegistrationContainer);
|
|
21
|
+
*/ const StytchPasskeyRegistration = /* @__PURE__ */ createB2CComponent('StytchPasskeyRegistration', PasskeyRegistrationContainer);
|
|
22
22
|
|
|
23
23
|
export { StytchPasskeyRegistration };
|
|
24
24
|
//# sourceMappingURL=StytchPasskeyRegistration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StytchPasskeyRegistration.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchPasskeyRegistration.tsx"],"sourcesContent":["import { PasskeyRegistrationContainer } from '../../b2c/PasskeyRegistrationContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\n\n/**\n * The Stytch Passkey Registration component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasskeyRegistration\n * presentation={{\n * theme: { primary: '#ff00f7' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasskeyRegistration = createB2CComponent('StytchPasskeyRegistration'
|
|
1
|
+
{"version":3,"file":"StytchPasskeyRegistration.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchPasskeyRegistration.tsx"],"sourcesContent":["import { PasskeyRegistrationContainer } from '../../b2c/PasskeyRegistrationContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\n\n/**\n * The Stytch Passkey Registration component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasskeyRegistration\n * presentation={{\n * theme: { primary: '#ff00f7' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasskeyRegistration = /* @__PURE__ */ createB2CComponent(\n 'StytchPasskeyRegistration',\n PasskeyRegistrationContainer,\n);\n"],"names":["StytchPasskeyRegistration","createB2CComponent","PasskeyRegistrationContainer"],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;AAiBC,IACM,MAAMA,yBAAAA,mBAA4CC,kBAAAA,CACvD,6BACAC,4BAAAA;;;;"}
|
|
@@ -26,7 +26,7 @@ import { createB2CComponent } from '../bindings/createB2CComponent.mjs';
|
|
|
26
26
|
* onEvent: (event) => console.log(event)
|
|
27
27
|
* }}
|
|
28
28
|
* />
|
|
29
|
-
*/ const StytchPasswordReset = createB2CComponent('StytchPasswordReset', ResetPasswordContainer);
|
|
29
|
+
*/ const StytchPasswordReset = /* @__PURE__ */ createB2CComponent('StytchPasswordReset', ResetPasswordContainer);
|
|
30
30
|
|
|
31
31
|
export { StytchPasswordReset };
|
|
32
32
|
//# sourceMappingURL=StytchPasswordReset.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StytchPasswordReset.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchPasswordReset.tsx"],"sourcesContent":["import { StytchProjectConfigurationInput } from '@stytch/core/public';\nimport { ResetPasswordContainer } from '../../b2c/ResetPasswordContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\nimport { StytchProps } from './StytchLogin';\n\nexport interface StytchResetPasswordProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StytchProps<TProjectConfiguration> {\n /**\n * A Stytch password reset token.\n */\n passwordResetToken: string;\n}\n\n/**\n * The Stytch Reset Password component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasswordReset\n * config={{\n * products: [Products.passwords],\n * passwordOptions: {\n * loginRedirectURL: '${exampleURL}/authenticate',\n * resetPasswordRedirectURL: '${exampleURL}/authenticate',\n * },\n * }}\n * passwordResetToken=\"PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs\"\n * presentation={{\n * theme: { primary: '#0577CA' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasswordReset = createB2CComponent('StytchPasswordReset', ResetPasswordContainer);\n"],"names":["StytchPasswordReset","createB2CComponent","ResetPasswordContainer"],"mappings":";;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBC,IACM,MAAMA,mBAAAA,
|
|
1
|
+
{"version":3,"file":"StytchPasswordReset.mjs","sources":["../../../../../../../../../web/src/ui/react/b2c/StytchPasswordReset.tsx"],"sourcesContent":["import { StytchProjectConfigurationInput } from '@stytch/core/public';\nimport { ResetPasswordContainer } from '../../b2c/ResetPasswordContainer';\nimport { createB2CComponent } from '../bindings/createB2CComponent';\nimport { StytchProps } from './StytchLogin';\n\nexport interface StytchResetPasswordProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StytchProps<TProjectConfiguration> {\n /**\n * A Stytch password reset token.\n */\n passwordResetToken: string;\n}\n\n/**\n * The Stytch Reset Password component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasswordReset\n * config={{\n * products: [Products.passwords],\n * passwordOptions: {\n * loginRedirectURL: '${exampleURL}/authenticate',\n * resetPasswordRedirectURL: '${exampleURL}/authenticate',\n * },\n * }}\n * passwordResetToken=\"PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs\"\n * presentation={{\n * theme: { primary: '#0577CA' },\n * options: {},\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasswordReset = /* @__PURE__ */ createB2CComponent('StytchPasswordReset', ResetPasswordContainer);\n"],"names":["StytchPasswordReset","createB2CComponent","ResetPasswordContainer"],"mappings":";;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBC,IACM,MAAMA,mBAAAA,mBAAsCC,kBAAAA,CAAmB,uBAAuBC,sBAAAA;;;;"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { RUN_IN_DEV } from '../../../../../core/src/utils/dev.mjs';
|
|
2
|
+
|
|
1
3
|
// The strings in this file are only for developers
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
function serverRenderError(name) {
|
|
5
|
+
RUN_IN_DEV(()=>{
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
throw new Error(`<${name} /> cannot be rendered on the server. If you are using Next.js, use the @stytch/nextjs package or 'use client' directives`);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
6
10
|
}
|
|
7
11
|
const noProviderError = (item, provider = 'StytchProvider')=>`${item} can only be used inside <${provider}>.`;
|
|
8
12
|
const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","sources":["../../../../../../../../../web/src/ui/react/utils/errors.ts"],"sourcesContent":["// The strings in this file are only for developers\n/* eslint-disable lingui/no-unlocalized-strings */\n\nexport function serverRenderError(name: string) {\n
|
|
1
|
+
{"version":3,"file":"errors.mjs","sources":["../../../../../../../../../web/src/ui/react/utils/errors.ts"],"sourcesContent":["// The strings in this file are only for developers\n/* eslint-disable lingui/no-unlocalized-strings */\n\nimport { RUN_IN_DEV } from '@stytch/core';\n\nexport function serverRenderError(name: string) {\n RUN_IN_DEV(() => {\n if (typeof window === 'undefined') {\n throw new Error(\n `<${name} /> cannot be rendered on the server. If you are using Next.js, use the @stytch/nextjs package or 'use client' directives`,\n );\n }\n });\n}\n\nexport const noProviderError = (item: string, provider = 'StytchProvider'): string =>\n `${item} can only be used inside <${provider}>.`;\n\nexport const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';\n\nexport const cannotInvokeMethodOnServerError = (path: string) =>\n process.env.NODE_ENV === 'production'\n ? `[Stytch] Invalid server-side function call to ${path}`\n : `[Stytch] Invalid server-side function call to ${path}.\nThe Stytch JavaScript SDK is intended to only be used on the client side.\nMake sure to wrap your API calls in a hook to ensure they are executed on the client.\n\n\\`\\`\\`\nconst myComponent = () => {\n const stytch = useStytch();\n // This will error out on the server.\n stytch.magicLinks.authenticate(...);\n useEffect(() => {\n // This will work well\n stytch.magicLinks.authenticate(...);\n }, []);\n}\n\\`\\`\\`\n\nIf you want to make API calls from server environments, please use the Stytch Node Library\nhttps://www.npmjs.com/package/stytch.`;\n"],"names":["serverRenderError","name","RUN_IN_DEV","window","Error","noProviderError","item","provider","providerMustBeUniqueError","cannotInvokeMethodOnServerError","path"],"mappings":";;AAAA;AAKO,SAASA,kBAAkBC,IAAY,EAAA;IAC5CC,UAAAA,CAAW,IAAA;QACT,IAAI,OAAOC,WAAW,WAAA,EAAa;AACjC,YAAA,MAAM,IAAIC,KAAAA,CACR,CAAC,CAAC,EAAEH,IAAAA,CAAK,yHAAyH,CAAC,CAAA;AAEvI,QAAA;AACF,IAAA,CAAA,CAAA;AACF;AAEO,MAAMI,eAAAA,GAAkB,CAACC,IAAAA,EAAcC,WAAW,gBAAgB,GACvE,CAAA,EAAGD,IAAAA,CAAK,0BAA0B,EAAEC,QAAAA,CAAS,EAAE;AAE1C,MAAMC,4BAA4B;AAElC,MAAMC,+BAAAA,GAAkC,CAACC,IAAAA,GAG1C,CAAC,8CAA8C,EAAEA,IAAAA,CAAK;;;;;;;;;;;;;;;;;AAiBvB,qCAAA;;;;"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { b as bs58Exports } from '../../../../_virtual/index3.mjs';
|
|
1
2
|
import 'react';
|
|
2
|
-
import { b as bs58Exports } from '../../../../_virtual/index4.mjs';
|
|
3
3
|
import { GenericWalletIcon } from '../assets/genericWallet.mjs';
|
|
4
|
-
import '../
|
|
5
|
-
import { BinanceIcon } from '../assets/logo-color/Binance.mjs';
|
|
6
|
-
import { CoinbaseIcon } from '../assets/logo-color/Coinbase.mjs';
|
|
7
|
-
import { MetamaskIcon } from '../assets/logo-color/Metamask.mjs';
|
|
8
|
-
import { PhantomIcon } from '../assets/logo-color/Phantom.mjs';
|
|
4
|
+
import { usePresentation, getButtonId } from '../ui/components/PresentationConfig.mjs';
|
|
9
5
|
import { Wallets } from '../../../core/src/public/ui.mjs';
|
|
10
6
|
|
|
11
7
|
const hasMultipleEthereumWallets = ()=>!!window.ethereum?.providers;
|
|
@@ -15,13 +11,22 @@ const hasOtherEthereumWallet = ()=>!hasMetaMask() && !hasCoinbaseWallet() && !!w
|
|
|
15
11
|
const getMetaMaskProvider = ()=>hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet)=>wallet.isMetaMask) : window.ethereum;
|
|
16
12
|
const getCoinbaseProvider = ()=>hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet)=>wallet.isCoinbaseWallet) : window.ethereum;
|
|
17
13
|
const getOtherInjectedProvider = ()=>window.ethereum.providers?.find((wallet)=>!wallet.isCoinbaseWallet && !wallet.isMetaMask);
|
|
18
|
-
const
|
|
19
|
-
[Wallets.Phantom]:
|
|
20
|
-
[Wallets.Binance]:
|
|
21
|
-
[Wallets.Coinbase]:
|
|
22
|
-
[Wallets.Metamask]:
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
const walletIcons = {
|
|
15
|
+
[Wallets.Phantom]: 'phantom',
|
|
16
|
+
[Wallets.Binance]: 'binance',
|
|
17
|
+
[Wallets.Coinbase]: 'coinbase',
|
|
18
|
+
[Wallets.Metamask]: 'metamask'
|
|
19
|
+
};
|
|
20
|
+
const useCryptoButtonProps = ()=>{
|
|
21
|
+
const presentation = usePresentation();
|
|
22
|
+
const iconRegistry = presentation.iconRegistry;
|
|
23
|
+
return {
|
|
24
|
+
getIcon: (wallet)=>{
|
|
25
|
+
const iconName = walletIcons[wallet];
|
|
26
|
+
return iconName ? iconRegistry[iconName] : GenericWalletIcon;
|
|
27
|
+
},
|
|
28
|
+
getId: (wallet)=>getButtonId(`wallet-${wallet}`, presentation.options)
|
|
29
|
+
};
|
|
25
30
|
};
|
|
26
31
|
const WalletToText = {
|
|
27
32
|
[Wallets.Phantom]: {
|
|
@@ -167,5 +172,5 @@ const isSolanaWallet = (wallet)=>{
|
|
|
167
172
|
return solanaWallets.includes(wallet);
|
|
168
173
|
};
|
|
169
174
|
|
|
170
|
-
export {
|
|
175
|
+
export { WalletToText, connectWithWallet, isSolanaWallet, isWalletVisible, signMessageWithWallet, useCryptoButtonProps, walletIcons };
|
|
171
176
|
//# sourceMappingURL=crypto.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.mjs","sources":["../../../../../../../web/src/utils/crypto.tsx"],"sourcesContent":["import { MessageDescriptor } from '@lingui/core';\nimport { msg } from '@lingui/core/macro';\nimport * as React from 'react';\nimport { Wallets } from '@stytch/core/public';\nimport { encode } from 'bs58';\n\nimport { GenericWalletIcon } from '../assets';\nimport { PhantomIcon, MetamaskIcon, BinanceIcon, CoinbaseIcon } from '../assets/logo-color';\n\ntype ProviderRequest = ({\n method,\n params,\n}: {\n method: 'eth_requestAccounts' | 'personal_sign';\n params?: string[];\n}) => string[] | string;\n\ntype ETHProvider = {\n isMetaMask?: boolean;\n isCoinbaseWallet?: boolean;\n request: ProviderRequest;\n};\n\ndeclare global {\n interface Window {\n solana: {\n isPhantom?: boolean;\n connect: () => { publicKey: { toString: () => string } };\n request: ({\n method,\n params,\n }: {\n method: 'signMessage';\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params: Record<string, any>;\n }) => { signature: Uint8Array };\n };\n\n ethereum: {\n isMetaMask?: boolean;\n isCoinbaseWallet?: boolean;\n request?: ({ method, params }: { method: string; params?: string[] }) => string[] | string;\n providers?: ETHProvider[];\n };\n\n BinanceChain: { request: ProviderRequest };\n }\n}\n\nconst hasMultipleEthereumWallets = () => !!window.ethereum?.providers;\n\nconst hasMetaMask = () =>\n !!(hasMultipleEthereumWallets()\n ? window.ethereum.providers?.find((wallet) => wallet.isMetaMask)\n : window.ethereum.isMetaMask);\n\nconst hasCoinbaseWallet = () =>\n !!(hasMultipleEthereumWallets()\n ? window.ethereum.providers?.find((wallet) => wallet.isCoinbaseWallet)\n : window.ethereum?.isCoinbaseWallet);\n\nconst hasOtherEthereumWallet = () => !hasMetaMask() && !hasCoinbaseWallet() && !!window.ethereum;\n\nconst getMetaMaskProvider = () =>\n hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet) => wallet.isMetaMask) : window.ethereum;\n\nconst getCoinbaseProvider = () =>\n hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet) => wallet.isCoinbaseWallet) : window.ethereum;\n\nconst getOtherInjectedProvider = () =>\n window.ethereum.providers?.find((wallet) => !wallet.isCoinbaseWallet && !wallet.isMetaMask);\n\nexport const WalletToIcon: Record<Wallets, React.FC> = {\n [Wallets.Phantom]: PhantomIcon,\n [Wallets.Binance]: BinanceIcon,\n [Wallets.Coinbase]: CoinbaseIcon,\n [Wallets.Metamask]: MetamaskIcon,\n [Wallets.GenericEthereumWallet]: GenericWalletIcon,\n [Wallets.GenericSolanaWallet]: GenericWalletIcon,\n};\n\nexport const WalletToText: Record<Wallets, MessageDescriptor> = {\n [Wallets.Phantom]: msg({ id: 'crypto.wallet.phantom', message: 'Phantom' }),\n [Wallets.Binance]: msg({ id: 'crypto.wallet.binance', message: 'Binance' }),\n [Wallets.Coinbase]: msg({ id: 'crypto.wallet.coinbase', message: 'Coinbase' }),\n [Wallets.Metamask]: msg({ id: 'crypto.wallet.metamask', message: 'Metamask' }),\n [Wallets.GenericEthereumWallet]: msg({ id: 'crypto.wallet.otherEthereum', message: 'Other Ethereum Wallet' }),\n [Wallets.GenericSolanaWallet]: msg({ id: 'crypto.wallet.otherSolana', message: 'Other Solana Wallet' }),\n};\n\nexport const isWalletVisible = (wallet: Wallets): boolean => {\n switch (wallet) {\n case Wallets.Metamask:\n return !!window.ethereum && hasMetaMask();\n case Wallets.Phantom:\n return (!!window.solana && window.solana?.isPhantom) ?? false;\n case Wallets.Binance:\n return !!window.BinanceChain;\n case Wallets.Coinbase:\n return !!window.ethereum && hasCoinbaseWallet();\n case Wallets.GenericEthereumWallet:\n return !!window.ethereum && hasOtherEthereumWallet();\n case Wallets.GenericSolanaWallet:\n return !!window.solana && !window.solana.isPhantom;\n default:\n return false;\n }\n};\n\nconst connectWithEthereumProvider = async (request: ProviderRequest): Promise<string> => {\n const [address] = await request({\n method: 'eth_requestAccounts',\n });\n return address;\n};\n\nexport const connectWithWallet = async ({ wallet }: { wallet: Wallets }): Promise<string> => {\n switch (wallet) {\n case Wallets.Metamask: {\n const provider = getMetaMaskProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.Phantom: {\n const connectResp = await window.solana.connect();\n return connectResp.publicKey.toString();\n }\n case Wallets.Binance: {\n const provider = window.BinanceChain;\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.Coinbase: {\n const provider = getCoinbaseProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.GenericEthereumWallet: {\n const provider = getOtherInjectedProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.GenericSolanaWallet: {\n const connectResp = await window.solana.connect();\n return connectResp.publicKey.toString();\n }\n default:\n return '';\n }\n};\n\nconst signMessageWithSolanaProvider = async (message: string): Promise<string> => {\n const encodedMessage = new TextEncoder().encode(message);\n const signResp = await window.solana.request({\n method: 'signMessage',\n params: {\n message: encodedMessage,\n display: 'utf8',\n },\n });\n return encode(signResp.signature);\n};\n\nconst signMessageWithEthereumProvider = async (\n request: ProviderRequest,\n message: string,\n address: string,\n): Promise<string> => {\n const signature = await request({\n method: 'personal_sign',\n params: [message, address],\n });\n return signature as string;\n};\n\nexport const signMessageWithWallet = async ({\n wallet,\n message,\n address,\n}: {\n wallet: Wallets;\n message: string;\n address: string;\n}): Promise<string> => {\n switch (wallet) {\n case Wallets.Phantom:\n case Wallets.GenericSolanaWallet:\n return signMessageWithSolanaProvider(message);\n case Wallets.Metamask: {\n const provider = getMetaMaskProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.Binance: {\n const provider = window.BinanceChain;\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.Coinbase: {\n const provider = getCoinbaseProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.GenericEthereumWallet: {\n const provider = getOtherInjectedProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n default:\n return '';\n }\n};\n\nexport const isSolanaWallet = (wallet: Wallets) => {\n const solanaWallets: Wallets[] = [Wallets.Phantom, Wallets.GenericSolanaWallet];\n return solanaWallets.includes(wallet);\n};\n\nexport const isEthereumWallet = (wallet: Wallets) => {\n const ethWallets: Wallets[] = [Wallets.Binance, Wallets.GenericEthereumWallet, Wallets.Coinbase, Wallets.Metamask];\n return ethWallets.includes(wallet);\n};\n"],"names":["hasMultipleEthereumWallets","window","ethereum","providers","hasMetaMask","find","wallet","isMetaMask","hasCoinbaseWallet","isCoinbaseWallet","hasOtherEthereumWallet","getMetaMaskProvider","getCoinbaseProvider","getOtherInjectedProvider","WalletToIcon","Wallets","Phantom","PhantomIcon","Binance","BinanceIcon","Coinbase","CoinbaseIcon","Metamask","MetamaskIcon","GenericEthereumWallet","GenericWalletIcon","GenericSolanaWallet","WalletToText","isWalletVisible","solana","isPhantom","BinanceChain","connectWithEthereumProvider","request","address","method","connectWithWallet","provider","connectResp","connect","publicKey","toString","signMessageWithSolanaProvider","message","encodedMessage","TextEncoder","encode","signResp","params","display","signature","signMessage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AAQW;AAAoB,KAAA;IAC/E,OAAO4B,aAAAA,CAAcC,QAAQ,CAACjD,MAAAA,CAAAA;AAChC;;;;"}
|
|
1
|
+
{"version":3,"file":"crypto.mjs","sources":["../../../../../../../web/src/utils/crypto.tsx"],"sourcesContent":["import { MessageDescriptor } from '@lingui/core';\nimport { msg } from '@lingui/core/macro';\nimport { Wallets } from '@stytch/core/public';\nimport { encode } from 'bs58';\n\nimport { GenericWalletIcon } from '../assets';\nimport { cryptoIcons } from '../ui/b2c/components/Icons';\nimport { IconRegistry } from '../ui/components/IconRegistry';\nimport { getButtonId, usePresentation } from '../ui/components/PresentationConfig';\n\ntype ProviderRequest = ({\n method,\n params,\n}: {\n method: 'eth_requestAccounts' | 'personal_sign';\n params?: string[];\n}) => string[] | string;\n\ntype ETHProvider = {\n isMetaMask?: boolean;\n isCoinbaseWallet?: boolean;\n request: ProviderRequest;\n};\n\ndeclare global {\n interface Window {\n solana: {\n isPhantom?: boolean;\n connect: () => { publicKey: { toString: () => string } };\n request: ({\n method,\n params,\n }: {\n method: 'signMessage';\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params: Record<string, any>;\n }) => { signature: Uint8Array };\n };\n\n ethereum: {\n isMetaMask?: boolean;\n isCoinbaseWallet?: boolean;\n request?: ({ method, params }: { method: string; params?: string[] }) => string[] | string;\n providers?: ETHProvider[];\n };\n\n BinanceChain: { request: ProviderRequest };\n }\n}\n\nconst hasMultipleEthereumWallets = () => !!window.ethereum?.providers;\n\nconst hasMetaMask = () =>\n !!(hasMultipleEthereumWallets()\n ? window.ethereum.providers?.find((wallet) => wallet.isMetaMask)\n : window.ethereum.isMetaMask);\n\nconst hasCoinbaseWallet = () =>\n !!(hasMultipleEthereumWallets()\n ? window.ethereum.providers?.find((wallet) => wallet.isCoinbaseWallet)\n : window.ethereum?.isCoinbaseWallet);\n\nconst hasOtherEthereumWallet = () => !hasMetaMask() && !hasCoinbaseWallet() && !!window.ethereum;\n\nconst getMetaMaskProvider = () =>\n hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet) => wallet.isMetaMask) : window.ethereum;\n\nconst getCoinbaseProvider = () =>\n hasMultipleEthereumWallets() ? window.ethereum.providers?.find((wallet) => wallet.isCoinbaseWallet) : window.ethereum;\n\nconst getOtherInjectedProvider = () =>\n window.ethereum.providers?.find((wallet) => !wallet.isCoinbaseWallet && !wallet.isMetaMask);\n\ntype CryptoIcon = keyof typeof cryptoIcons;\nexport const walletIcons: Partial<Record<Wallets, CryptoIcon>> = {\n [Wallets.Phantom]: 'phantom',\n [Wallets.Binance]: 'binance',\n [Wallets.Coinbase]: 'coinbase',\n [Wallets.Metamask]: 'metamask',\n};\n\nexport const useCryptoButtonProps = () => {\n const presentation = usePresentation();\n const iconRegistry: IconRegistry<CryptoIcon> = presentation.iconRegistry;\n\n return {\n getIcon: (wallet: Wallets) => {\n const iconName = walletIcons[wallet];\n return iconName ? iconRegistry[iconName] : GenericWalletIcon;\n },\n getId: (wallet: Wallets) => getButtonId(`wallet-${wallet}`, presentation.options),\n };\n};\n\nexport const WalletToText: Record<Wallets, MessageDescriptor> = {\n [Wallets.Phantom]: msg({ id: 'crypto.wallet.phantom', message: 'Phantom' }),\n [Wallets.Binance]: msg({ id: 'crypto.wallet.binance', message: 'Binance' }),\n [Wallets.Coinbase]: msg({ id: 'crypto.wallet.coinbase', message: 'Coinbase' }),\n [Wallets.Metamask]: msg({ id: 'crypto.wallet.metamask', message: 'Metamask' }),\n [Wallets.GenericEthereumWallet]: msg({ id: 'crypto.wallet.otherEthereum', message: 'Other Ethereum Wallet' }),\n [Wallets.GenericSolanaWallet]: msg({ id: 'crypto.wallet.otherSolana', message: 'Other Solana Wallet' }),\n};\n\nexport const isWalletVisible = (wallet: Wallets): boolean => {\n switch (wallet) {\n case Wallets.Metamask:\n return !!window.ethereum && hasMetaMask();\n case Wallets.Phantom:\n return (!!window.solana && window.solana?.isPhantom) ?? false;\n case Wallets.Binance:\n return !!window.BinanceChain;\n case Wallets.Coinbase:\n return !!window.ethereum && hasCoinbaseWallet();\n case Wallets.GenericEthereumWallet:\n return !!window.ethereum && hasOtherEthereumWallet();\n case Wallets.GenericSolanaWallet:\n return !!window.solana && !window.solana.isPhantom;\n default:\n return false;\n }\n};\n\nconst connectWithEthereumProvider = async (request: ProviderRequest): Promise<string> => {\n const [address] = await request({\n method: 'eth_requestAccounts',\n });\n return address;\n};\n\nexport const connectWithWallet = async ({ wallet }: { wallet: Wallets }): Promise<string> => {\n switch (wallet) {\n case Wallets.Metamask: {\n const provider = getMetaMaskProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.Phantom: {\n const connectResp = await window.solana.connect();\n return connectResp.publicKey.toString();\n }\n case Wallets.Binance: {\n const provider = window.BinanceChain;\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.Coinbase: {\n const provider = getCoinbaseProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.GenericEthereumWallet: {\n const provider = getOtherInjectedProvider();\n return provider?.request ? connectWithEthereumProvider(provider?.request) : '';\n }\n case Wallets.GenericSolanaWallet: {\n const connectResp = await window.solana.connect();\n return connectResp.publicKey.toString();\n }\n default:\n return '';\n }\n};\n\nconst signMessageWithSolanaProvider = async (message: string): Promise<string> => {\n const encodedMessage = new TextEncoder().encode(message);\n const signResp = await window.solana.request({\n method: 'signMessage',\n params: {\n message: encodedMessage,\n display: 'utf8',\n },\n });\n return encode(signResp.signature);\n};\n\nconst signMessageWithEthereumProvider = async (\n request: ProviderRequest,\n message: string,\n address: string,\n): Promise<string> => {\n const signature = await request({\n method: 'personal_sign',\n params: [message, address],\n });\n return signature as string;\n};\n\nexport const signMessageWithWallet = async ({\n wallet,\n message,\n address,\n}: {\n wallet: Wallets;\n message: string;\n address: string;\n}): Promise<string> => {\n switch (wallet) {\n case Wallets.Phantom:\n case Wallets.GenericSolanaWallet:\n return signMessageWithSolanaProvider(message);\n case Wallets.Metamask: {\n const provider = getMetaMaskProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.Binance: {\n const provider = window.BinanceChain;\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.Coinbase: {\n const provider = getCoinbaseProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n case Wallets.GenericEthereumWallet: {\n const provider = getOtherInjectedProvider();\n return provider?.request ? signMessageWithEthereumProvider(provider?.request, message, address) : '';\n }\n default:\n return '';\n }\n};\n\nexport const isSolanaWallet = (wallet: Wallets) => {\n const solanaWallets: Wallets[] = [Wallets.Phantom, Wallets.GenericSolanaWallet];\n return solanaWallets.includes(wallet);\n};\n\nexport const isEthereumWallet = (wallet: Wallets) => {\n const ethWallets: Wallets[] = [Wallets.Binance, Wallets.GenericEthereumWallet, Wallets.Coinbase, Wallets.Metamask];\n return ethWallets.includes(wallet);\n};\n"],"names":["hasMultipleEthereumWallets","window","ethereum","providers","hasMetaMask","find","wallet","isMetaMask","hasCoinbaseWallet","isCoinbaseWallet","hasOtherEthereumWallet","getMetaMaskProvider","getCoinbaseProvider","getOtherInjectedProvider","walletIcons","Wallets","Phantom","Binance","Coinbase","Metamask","useCryptoButtonProps","presentation","usePresentation","iconRegistry","getIcon","iconName","GenericWalletIcon","getId","getButtonId","options","WalletToText","GenericEthereumWallet","GenericSolanaWallet","isWalletVisible","solana","isPhantom","BinanceChain","connectWithEthereumProvider","request","address","method","connectWithWallet","provider","connectResp","connect","publicKey","toString","signMessageWithSolanaProvider","message","encodedMessage","TextEncoder","encode","signResp","params","display","signature","signMessageWithEthereumProvider","signMessageWithWallet","isSolanaWallet","solanaWallets","includes"],"mappings":";;;;;;AAkDA,MAAMA,6BAA6B,IAAM,CAAC,CAACC,MAAAA,CAAOC,QAAQ,EAAEC,SAAAA;AAE5D,MAAMC,WAAAA,GAAc,IAClB,CAAC,EAAEJ,0BAAAA,EAAAA,GACCC,MAA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,EAAA;AACX;AACF;AAEO,MAAMmB,iBAAiB,CAACpD,MAAAA,GAAAA;AAC7B,IAAA,MAAMqD,aAAAA,GAA2B;AAAC5C,QAAAA,OAAAA,CAAQC,OAAO;AAAED,QAAAA,OAAAA,CAAQiB;AAAoB,KAAA;IAC/E,OAAO2B,aAAAA,CAAcC,QAAQ,CAACtD,MAAAA,CAAAA;AAChC;;;;"}
|
|
@@ -10,7 +10,7 @@ const getParamsFromB2BOAuthProviderConfig = (provider)=>{
|
|
|
10
10
|
providerType = provider;
|
|
11
11
|
} else {
|
|
12
12
|
providerType = provider.type;
|
|
13
|
-
if (provider.type === B2BOAuthProviders.Google &&
|
|
13
|
+
if (provider.type === B2BOAuthProviders.Google && provider.one_tap) {
|
|
14
14
|
oneTap = provider.one_tap;
|
|
15
15
|
cancelOnTapOutside = provider.cancel_on_tap_outside;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauthProviderType.mjs","sources":["../../../../../../../web/src/utils/oauthProviderType.ts"],"sourcesContent":["import { B2BOAuthProviderConfig, B2BOAuthProviders } from '@stytch/core/public';\n\nexport const getParamsFromB2BOAuthProviderConfig = (provider: B2BOAuthProviderConfig) => {\n let providerType: B2BOAuthProviders;\n let oneTap = false;\n let customScopes: string[] = [];\n let providerParams: Record<string, string> = {};\n let cancelOnTapOutside: boolean | undefined = undefined;\n if (typeof provider === 'string') {\n providerType = provider;\n } else {\n providerType = provider.type;\n if (provider.type === B2BOAuthProviders.Google &&
|
|
1
|
+
{"version":3,"file":"oauthProviderType.mjs","sources":["../../../../../../../web/src/utils/oauthProviderType.ts"],"sourcesContent":["import { B2BOAuthProviderConfig, B2BOAuthProviders } from '@stytch/core/public';\n\nexport const getParamsFromB2BOAuthProviderConfig = (provider: B2BOAuthProviderConfig) => {\n let providerType: B2BOAuthProviders;\n let oneTap = false;\n let customScopes: string[] = [];\n let providerParams: Record<string, string> = {};\n let cancelOnTapOutside: boolean | undefined = undefined;\n if (typeof provider === 'string') {\n providerType = provider;\n } else {\n providerType = provider.type;\n if (provider.type === B2BOAuthProviders.Google && provider.one_tap) {\n oneTap = provider.one_tap;\n cancelOnTapOutside = provider.cancel_on_tap_outside;\n }\n customScopes = provider.customScopes || [];\n providerParams = provider.providerParams || {};\n }\n return {\n type: providerType,\n one_tap: oneTap,\n customScopes,\n providerParams,\n cancel_on_tap_outside: cancelOnTapOutside,\n };\n};\n"],"names":["getParamsFromB2BOAuthProviderConfig","provider","providerType","oneTap","customScopes","providerParams","cancelOnTapOutside","undefined","type","B2BOAuthProviders","Google","one_tap","cancel_on_tap_outside"],"mappings":";;AAEO,MAAMA,sCAAsC,CAACC,QAAAA,GAAAA;IAClD,IAAIC,YAAAA;AACJ,IAAA,IAAIC,MAAAA,GAAS,KAAA;AACb,IAAA,IAAIC,eAAyB,EAAE;AAC/B,IAAA,IAAIC,iBAAyC,EAAC;AAC9C,IAAA,IAAIC,kBAAAA,GAA0CC,SAAAA;IAC9C,IAAI,OAAON,aAAa,QAAA,EAAU;QAChCC,YAAAA,GAAeD,QAAAA;IACjB,CAAA,MAAO;AACLC,QAAAA,YAAAA,GAAeD,SAASO,IAAI;QAC5B,IAAIP,QAAAA,CAASO,IAAI,KAAKC,iBAAAA,CAAkBC,MAAM,IAAIT,QAAAA,CAASU,OAAO,EAAE;AAClER,YAAAA,MAAAA,GAASF,SAASU,OAAO;AACzBL,YAAAA,kBAAAA,GAAqBL,SAASW,qBAAqB;AACrD,QAAA;QACAR,YAAAA,GAAeH,QAAAA,CAASG,YAAY,IAAI,EAAE;QAC1CC,cAAAA,GAAiBJ,QAAAA,CAASI,cAAc,IAAI,EAAC;AAC/C,IAAA;IACA,OAAO;QACLG,IAAAA,EAAMN,YAAAA;QACNS,OAAAA,EAASR,MAAAA;AACTC,QAAAA,YAAAA;AACAC,QAAAA,cAAAA;QACAO,qBAAAA,EAAuBN;AACzB,KAAA;AACF;;;;"}
|