@terreno/syncdb 57.21.0 → 58.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -0
- package/README.md +8 -8
- package/dist/api/apiError.d.ts +43 -0
- package/dist/api/apiError.d.ts.map +1 -0
- package/dist/api/apiError.js +28 -0
- package/dist/api/apiError.js.map +1 -0
- package/dist/api/apiFetch.d.ts +44 -0
- package/dist/api/apiFetch.d.ts.map +1 -0
- package/dist/api/apiFetch.js +203 -0
- package/dist/api/apiFetch.js.map +1 -0
- package/dist/api/client.d.ts +70 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +240 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/client.test.d.ts +2 -0
- package/dist/api/client.test.d.ts.map +1 -0
- package/dist/api/client.test.js +588 -0
- package/dist/api/client.test.js.map +1 -0
- package/dist/app/app.d.ts +13 -0
- package/dist/app/app.d.ts.map +1 -0
- package/dist/app/app.js +13 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/devConsoleLogger.d.ts +18 -0
- package/dist/app/devConsoleLogger.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.js +147 -0
- package/dist/app/devConsoleLogger.js.map +1 -0
- package/dist/app/devConsoleLogger.test.d.ts +2 -0
- package/dist/app/devConsoleLogger.test.d.ts.map +1 -0
- package/dist/app/devConsoleLogger.test.js +202 -0
- package/dist/app/devConsoleLogger.test.js.map +1 -0
- package/dist/app/mcpTools.d.ts +32 -0
- package/dist/app/mcpTools.d.ts.map +1 -0
- package/dist/app/mcpTools.js +61 -0
- package/dist/app/mcpTools.js.map +1 -0
- package/dist/app/permissions.d.ts +26 -0
- package/dist/app/permissions.d.ts.map +1 -0
- package/dist/app/permissions.js +37 -0
- package/dist/app/permissions.js.map +1 -0
- package/dist/app/permissions.test.d.ts +2 -0
- package/dist/app/permissions.test.d.ts.map +1 -0
- package/dist/app/permissions.test.js +36 -0
- package/dist/app/permissions.test.js.map +1 -0
- package/dist/app/upgradeCheck.d.ts +46 -0
- package/dist/app/upgradeCheck.d.ts.map +1 -0
- package/dist/app/upgradeCheck.js +121 -0
- package/dist/app/upgradeCheck.js.map +1 -0
- package/dist/auth/SessionProvider.d.ts +40 -0
- package/dist/auth/SessionProvider.d.ts.map +1 -0
- package/dist/auth/SessionProvider.js +44 -0
- package/dist/auth/SessionProvider.js.map +1 -0
- package/dist/auth/SessionProvider.test.d.ts +2 -0
- package/dist/auth/SessionProvider.test.d.ts.map +1 -0
- package/dist/auth/SessionProvider.test.js +240 -0
- package/dist/auth/SessionProvider.test.js.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts +25 -0
- package/dist/auth/TerrenoAccountSecurityScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js +21 -0
- package/dist/auth/TerrenoAccountSecurityScreen.js.map +1 -0
- package/dist/auth/TerrenoLoginScreen.d.ts +62 -0
- package/dist/auth/TerrenoLoginScreen.d.ts.map +1 -0
- package/dist/auth/TerrenoLoginScreen.js +45 -0
- package/dist/auth/TerrenoLoginScreen.js.map +1 -0
- package/dist/auth/auth.d.ts +36 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +35 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/betterAuthAdapter.d.ts +1 -1
- package/dist/auth/betterAuthClient.d.ts +276 -0
- package/dist/auth/betterAuthClient.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.js +744 -0
- package/dist/auth/betterAuthClient.js.map +1 -0
- package/dist/auth/betterAuthClient.types.test.d.ts +2 -0
- package/dist/auth/betterAuthClient.types.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClient.types.test.js +151 -0
- package/dist/auth/betterAuthClient.types.test.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.d.ts +51 -0
- package/dist/auth/betterAuthClientRegistry.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.js +69 -0
- package/dist/auth/betterAuthClientRegistry.js.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts +2 -0
- package/dist/auth/betterAuthClientRegistry.test.d.ts.map +1 -0
- package/dist/auth/betterAuthClientRegistry.test.js +91 -0
- package/dist/auth/betterAuthClientRegistry.test.js.map +1 -0
- package/dist/auth/betterAuthTypes.d.ts +172 -0
- package/dist/auth/betterAuthTypes.d.ts.map +1 -0
- package/dist/auth/betterAuthTypes.js +7 -0
- package/dist/auth/betterAuthTypes.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.d.ts +102 -0
- package/dist/auth/jwtAuthAdapter.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.js +282 -0
- package/dist/auth/jwtAuthAdapter.js.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts +2 -0
- package/dist/auth/jwtAuthAdapter.test.d.ts.map +1 -0
- package/dist/auth/jwtAuthAdapter.test.js +614 -0
- package/dist/auth/jwtAuthAdapter.test.js.map +1 -0
- package/dist/auth/loginErrors.d.ts +75 -0
- package/dist/auth/loginErrors.d.ts.map +1 -0
- package/dist/auth/loginErrors.js +154 -0
- package/dist/auth/loginErrors.js.map +1 -0
- package/dist/auth/loginErrors.test.d.ts +2 -0
- package/dist/auth/loginErrors.test.d.ts.map +1 -0
- package/dist/auth/loginErrors.test.js +70 -0
- package/dist/auth/loginErrors.test.js.map +1 -0
- package/dist/auth/ownEntry.d.ts +8 -0
- package/dist/auth/ownEntry.d.ts.map +1 -0
- package/dist/auth/ownEntry.js +13 -0
- package/dist/auth/ownEntry.js.map +1 -0
- package/dist/auth/ownEntry.test.d.ts +2 -0
- package/dist/auth/ownEntry.test.d.ts.map +1 -0
- package/dist/auth/ownEntry.test.js +18 -0
- package/dist/auth/ownEntry.test.js.map +1 -0
- package/dist/auth/platform.d.ts +3 -0
- package/dist/auth/platform.d.ts.map +1 -0
- package/dist/auth/platform.js +4 -0
- package/dist/auth/platform.js.map +1 -0
- package/dist/auth/rememberedAccounts.d.ts +126 -0
- package/dist/auth/rememberedAccounts.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.js +399 -0
- package/dist/auth/rememberedAccounts.js.map +1 -0
- package/dist/auth/rememberedAccounts.test.d.ts +2 -0
- package/dist/auth/rememberedAccounts.test.d.ts.map +1 -0
- package/dist/auth/rememberedAccounts.test.js +676 -0
- package/dist/auth/rememberedAccounts.test.js.map +1 -0
- package/dist/auth/session.d.ts +118 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +370 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/session.test.d.ts +2 -0
- package/dist/auth/session.test.d.ts.map +1 -0
- package/dist/auth/session.test.js +825 -0
- package/dist/auth/session.test.js.map +1 -0
- package/dist/auth/tokenExpiry.d.ts +70 -0
- package/dist/auth/tokenExpiry.d.ts.map +1 -0
- package/dist/auth/tokenExpiry.js +123 -0
- package/dist/auth/tokenExpiry.js.map +1 -0
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/auth/useAccountSecurity.d.ts +183 -0
- package/dist/auth/useAccountSecurity.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.js +399 -0
- package/dist/auth/useAccountSecurity.js.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts +2 -0
- package/dist/auth/useAccountSecurity.types.test.d.ts.map +1 -0
- package/dist/auth/useAccountSecurity.types.test.js +21 -0
- package/dist/auth/useAccountSecurity.types.test.js.map +1 -0
- package/dist/auth/useAuthMethods.d.ts +67 -0
- package/dist/auth/useAuthMethods.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.js +77 -0
- package/dist/auth/useAuthMethods.js.map +1 -0
- package/dist/auth/useAuthMethods.test.d.ts +2 -0
- package/dist/auth/useAuthMethods.test.d.ts.map +1 -0
- package/dist/auth/useAuthMethods.test.js +145 -0
- package/dist/auth/useAuthMethods.test.js.map +1 -0
- package/dist/auth/useJwtAuth.d.ts +31 -0
- package/dist/auth/useJwtAuth.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.js +58 -0
- package/dist/auth/useJwtAuth.js.map +1 -0
- package/dist/auth/useJwtAuth.test.d.ts +2 -0
- package/dist/auth/useJwtAuth.test.d.ts.map +1 -0
- package/dist/auth/useJwtAuth.test.js +165 -0
- package/dist/auth/useJwtAuth.test.js.map +1 -0
- package/dist/auth/useLoginController.d.ts +248 -0
- package/dist/auth/useLoginController.d.ts.map +1 -0
- package/dist/auth/useLoginController.js +671 -0
- package/dist/auth/useLoginController.js.map +1 -0
- package/dist/auth/useLoginController.types.test.d.ts +2 -0
- package/dist/auth/useLoginController.types.test.d.ts.map +1 -0
- package/dist/auth/useLoginController.types.test.js +19 -0
- package/dist/auth/useLoginController.types.test.js.map +1 -0
- package/dist/buildNumber.d.ts +34 -0
- package/dist/buildNumber.d.ts.map +1 -0
- package/dist/buildNumber.js +62 -0
- package/dist/buildNumber.js.map +1 -0
- package/dist/buildNumber.test.d.ts +2 -0
- package/dist/buildNumber.test.d.ts.map +1 -0
- package/dist/buildNumber.test.js +114 -0
- package/dist/buildNumber.test.js.map +1 -0
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -185
- package/dist/client.js.map +1 -1
- package/dist/client.socketEvents.test.d.ts +2 -0
- package/dist/client.socketEvents.test.d.ts.map +1 -0
- package/dist/client.socketEvents.test.js +64 -0
- package/dist/client.socketEvents.test.js.map +1 -0
- package/dist/client.test.js +87 -1
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/cli.js +23 -12
- package/dist/codegen/cli.js.map +1 -1
- package/dist/codegen/cli.test.js +57 -0
- package/dist/codegen/cli.test.js.map +1 -1
- package/dist/codegen/discoverCollections.d.ts.map +1 -1
- package/dist/codegen/discoverCollections.js +4 -0
- package/dist/codegen/discoverCollections.js.map +1 -1
- package/dist/codegen/discoverOperations.d.ts +11 -0
- package/dist/codegen/discoverOperations.d.ts.map +1 -0
- package/dist/codegen/discoverOperations.js +135 -0
- package/dist/codegen/discoverOperations.js.map +1 -0
- package/dist/codegen/emitApi.d.ts +8 -0
- package/dist/codegen/emitApi.d.ts.map +1 -0
- package/dist/codegen/emitApi.js +312 -0
- package/dist/codegen/emitApi.js.map +1 -0
- package/dist/codegen/emitApi.test.d.ts +2 -0
- package/dist/codegen/emitApi.test.d.ts.map +1 -0
- package/dist/codegen/emitApi.test.js +360 -0
- package/dist/codegen/emitApi.test.js.map +1 -0
- package/dist/codegen/emitSdk.js +2 -2
- package/dist/codegen/generate.d.ts +6 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +18 -0
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/generate.test.js +53 -1
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/hookNames.d.ts +11 -0
- package/dist/codegen/hookNames.d.ts.map +1 -1
- package/dist/codegen/hookNames.js +23 -0
- package/dist/codegen/hookNames.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -1
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +7 -2
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +9 -0
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +46 -1
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/config/baseUrl.d.ts +13 -0
- package/dist/config/baseUrl.d.ts.map +1 -0
- package/dist/config/baseUrl.js +49 -0
- package/dist/config/baseUrl.js.map +1 -0
- package/dist/config/baseUrl.test.d.ts +2 -0
- package/dist/config/baseUrl.test.d.ts.map +1 -0
- package/dist/config/baseUrl.test.js +42 -0
- package/dist/config/baseUrl.test.js.map +1 -0
- package/dist/config/resolveBaseUrls.d.ts +53 -0
- package/dist/config/resolveBaseUrls.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.js +80 -0
- package/dist/config/resolveBaseUrls.js.map +1 -0
- package/dist/config/resolveBaseUrls.test.d.ts +2 -0
- package/dist/config/resolveBaseUrls.test.d.ts.map +1 -0
- package/dist/config/resolveBaseUrls.test.js +265 -0
- package/dist/config/resolveBaseUrls.test.js.map +1 -0
- package/dist/crypto/keyProviders.d.ts +2 -2
- package/dist/crypto/keyProviders.d.ts.map +1 -1
- package/dist/crypto/keyProviders.js +15 -4
- package/dist/crypto/keyProviders.js.map +1 -1
- package/dist/crypto/keyProviders.test.js +19 -0
- package/dist/crypto/keyProviders.test.js.map +1 -1
- package/dist/crypto/types.d.ts +5 -0
- package/dist/crypto/types.d.ts.map +1 -1
- package/dist/flags/flagTestServer.d.ts +19 -0
- package/dist/flags/flagTestServer.d.ts.map +1 -0
- package/dist/flags/flagTestServer.js +58 -0
- package/dist/flags/flagTestServer.js.map +1 -0
- package/dist/flags/useFeatureFlags.d.ts +30 -0
- package/dist/flags/useFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.js +83 -0
- package/dist/flags/useFeatureFlags.js.map +1 -0
- package/dist/flags/useFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useFeatureFlags.test.js +116 -0
- package/dist/flags/useFeatureFlags.test.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts +50 -0
- package/dist/flags/useTerrenoFeatureFlags.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.js +125 -0
- package/dist/flags/useTerrenoFeatureFlags.js.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts +2 -0
- package/dist/flags/useTerrenoFeatureFlags.test.d.ts.map +1 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js +259 -0
- package/dist/flags/useTerrenoFeatureFlags.test.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js +94 -0
- package/dist/isolated/TerrenoAccountSecurityScreen.isolated.js.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts +2 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.d.ts.map +1 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js +183 -0
- package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.isolated.js +1734 -0
- package/dist/isolated/betterAuthClient.isolated.js.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts +2 -0
- package/dist/isolated/betterAuthClient.native.isolated.d.ts.map +1 -0
- package/dist/isolated/betterAuthClient.native.isolated.js +153 -0
- package/dist/isolated/betterAuthClient.native.isolated.js.map +1 -0
- package/dist/isolated/mcpTools.isolated.d.ts +2 -0
- package/dist/isolated/mcpTools.isolated.d.ts.map +1 -0
- package/dist/isolated/mcpTools.isolated.js +197 -0
- package/dist/isolated/mcpTools.isolated.js.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts +2 -0
- package/dist/isolated/rememberedAccounts.native.isolated.d.ts.map +1 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js +50 -0
- package/dist/isolated/rememberedAccounts.native.isolated.js.map +1 -0
- package/dist/isolated/sessionLogout.isolated.d.ts +2 -0
- package/dist/isolated/sessionLogout.isolated.d.ts.map +1 -0
- package/dist/isolated/sessionLogout.isolated.js +133 -0
- package/dist/isolated/sessionLogout.isolated.js.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts +2 -0
- package/dist/isolated/tokenExpiry.isolated.d.ts.map +1 -0
- package/dist/isolated/tokenExpiry.isolated.js +232 -0
- package/dist/isolated/tokenExpiry.isolated.js.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts +2 -0
- package/dist/isolated/upgradeCheck.isolated.d.ts.map +1 -0
- package/dist/isolated/upgradeCheck.isolated.js +241 -0
- package/dist/isolated/upgradeCheck.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.isolated.js +851 -0
- package/dist/isolated/useAccountSecurity.isolated.js.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts +2 -0
- package/dist/isolated/useAccountSecurity.native.isolated.d.ts.map +1 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js +52 -0
- package/dist/isolated/useAccountSecurity.native.isolated.js.map +1 -0
- package/dist/isolated/useLoginController.isolated.d.ts +2 -0
- package/dist/isolated/useLoginController.isolated.d.ts.map +1 -0
- package/dist/isolated/useLoginController.isolated.js +1116 -0
- package/dist/isolated/useLoginController.isolated.js.map +1 -0
- package/dist/mutations/entityIds.d.ts +23 -0
- package/dist/mutations/entityIds.d.ts.map +1 -0
- package/dist/mutations/entityIds.js +31 -0
- package/dist/mutations/entityIds.js.map +1 -0
- package/dist/mutations/entityIds.test.d.ts +2 -0
- package/dist/mutations/entityIds.test.d.ts.map +1 -0
- package/dist/mutations/entityIds.test.js +48 -0
- package/dist/mutations/entityIds.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -1
- package/dist/persisters/defaultPersisterFactory.native.js +2 -0
- package/dist/persisters/defaultPersisterFactory.native.js.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -1
- package/dist/persisters/encryptedIndexedDbPersister.js +3 -0
- package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -1
- package/dist/persisters/types.d.ts +6 -0
- package/dist/persisters/types.d.ts.map +1 -1
- package/dist/query/queryWindows.js +2 -2
- package/dist/query/queryWindows.js.map +1 -1
- package/dist/react/apiHooks.d.ts +87 -0
- package/dist/react/apiHooks.d.ts.map +1 -0
- package/dist/react/apiHooks.js +195 -0
- package/dist/react/apiHooks.js.map +1 -0
- package/dist/react/apiHooks.test.d.ts +2 -0
- package/dist/react/apiHooks.test.d.ts.map +1 -0
- package/dist/react/apiHooks.test.js +366 -0
- package/dist/react/apiHooks.test.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -0
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +2 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useSocketEvent.d.ts +27 -0
- package/dist/react/useSocketEvent.d.ts.map +1 -0
- package/dist/react/useSocketEvent.js +36 -0
- package/dist/react/useSocketEvent.js.map +1 -0
- package/dist/react/useSocketEvent.test.d.ts +2 -0
- package/dist/react/useSocketEvent.test.d.ts.map +1 -0
- package/dist/react/useSocketEvent.test.js +76 -0
- package/dist/react/useSocketEvent.test.js.map +1 -0
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +5 -4
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +14 -1
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +42 -0
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +9 -0
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/transport.js +13 -0
- package/dist/sync/transport.js.map +1 -1
- package/dist/testing/fakeTransport.d.ts +5 -1
- package/dist/testing/fakeTransport.d.ts.map +1 -1
- package/dist/testing/fakeTransport.js +26 -0
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/testing/fakeTransport.test.js +15 -0
- package/dist/testing/fakeTransport.test.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +93 -8
- package/src/api/apiError.ts +47 -0
- package/src/api/apiFetch.ts +245 -0
- package/src/api/client.test.ts +711 -0
- package/src/api/client.ts +367 -0
- package/src/app/app.ts +30 -0
- package/src/app/devConsoleLogger.test.ts +246 -0
- package/src/app/devConsoleLogger.ts +173 -0
- package/src/app/mcpTools.ts +101 -0
- package/src/app/permissions.test.ts +44 -0
- package/src/app/permissions.ts +58 -0
- package/src/app/upgradeCheck.ts +177 -0
- package/src/auth/SessionProvider.test.tsx +286 -0
- package/src/auth/SessionProvider.tsx +87 -0
- package/src/auth/TerrenoAccountSecurityScreen.tsx +56 -0
- package/src/auth/TerrenoLoginScreen.tsx +131 -0
- package/src/auth/auth.ts +117 -0
- package/src/auth/betterAuthAdapter.ts +1 -1
- package/src/auth/betterAuthClient.ts +997 -0
- package/src/auth/betterAuthClient.types.test.ts +197 -0
- package/src/auth/betterAuthClientRegistry.test.ts +114 -0
- package/src/auth/betterAuthClientRegistry.ts +99 -0
- package/src/auth/betterAuthTypes.ts +189 -0
- package/src/auth/jwtAuthAdapter.test.ts +754 -0
- package/src/auth/jwtAuthAdapter.ts +420 -0
- package/src/auth/loginErrors.test.ts +97 -0
- package/src/auth/loginErrors.ts +249 -0
- package/src/auth/ownEntry.test.ts +22 -0
- package/src/auth/ownEntry.ts +15 -0
- package/src/auth/platform.ts +4 -0
- package/src/auth/rememberedAccounts.test.ts +844 -0
- package/src/auth/rememberedAccounts.ts +568 -0
- package/src/auth/session.test.ts +976 -0
- package/src/auth/session.ts +509 -0
- package/src/auth/tokenExpiry.ts +185 -0
- package/src/auth/types.ts +1 -1
- package/src/auth/useAccountSecurity.ts +678 -0
- package/src/auth/useAccountSecurity.types.test.ts +28 -0
- package/src/auth/useAuthMethods.test.ts +181 -0
- package/src/auth/useAuthMethods.ts +137 -0
- package/src/auth/useJwtAuth.test.tsx +202 -0
- package/src/auth/useJwtAuth.ts +102 -0
- package/src/auth/useLoginController.ts +1038 -0
- package/src/auth/useLoginController.types.test.ts +26 -0
- package/src/buildNumber.test.ts +139 -0
- package/src/buildNumber.ts +75 -0
- package/src/client.socketEvents.test.ts +77 -0
- package/src/client.test.ts +109 -1
- package/src/client.ts +104 -19
- package/src/codegen/cli.test.ts +66 -0
- package/src/codegen/cli.ts +23 -12
- package/src/codegen/discoverCollections.ts +4 -0
- package/src/codegen/discoverOperations.ts +172 -0
- package/src/codegen/emitApi.test.tsx +445 -0
- package/src/codegen/emitApi.ts +396 -0
- package/src/codegen/emitSdk.ts +2 -2
- package/src/codegen/fixtures/openapi.api.json +840 -0
- package/src/codegen/generate.test.ts +54 -1
- package/src/codegen/generate.ts +20 -1
- package/src/codegen/hookNames.ts +35 -0
- package/src/codegen/safeIdentifiers.test.ts +20 -0
- package/src/codegen/safeIdentifiers.ts +7 -2
- package/src/codegen/types.ts +45 -1
- package/src/config/baseUrl.test.ts +53 -0
- package/src/config/baseUrl.ts +68 -0
- package/src/config/resolveBaseUrls.test.ts +308 -0
- package/src/config/resolveBaseUrls.ts +118 -0
- package/src/crypto/keyProviders.test.ts +23 -0
- package/src/crypto/keyProviders.ts +15 -4
- package/src/crypto/types.ts +5 -0
- package/src/flags/flagTestServer.ts +77 -0
- package/src/flags/useFeatureFlags.test.tsx +146 -0
- package/src/flags/useFeatureFlags.ts +130 -0
- package/src/flags/useTerrenoFeatureFlags.test.tsx +329 -0
- package/src/flags/useTerrenoFeatureFlags.ts +188 -0
- package/src/index.ts +4 -1
- package/src/isolated/TerrenoAccountSecurityScreen.isolated.tsx +123 -0
- package/src/isolated/TerrenoLoginScreen.isolated.tsx +256 -0
- package/src/isolated/betterAuthClient.isolated.ts +2198 -0
- package/src/isolated/betterAuthClient.native.isolated.ts +173 -0
- package/src/isolated/mcpTools.isolated.ts +259 -0
- package/src/isolated/rememberedAccounts.native.isolated.ts +63 -0
- package/src/isolated/sessionLogout.isolated.ts +152 -0
- package/src/isolated/tokenExpiry.isolated.ts +271 -0
- package/src/isolated/upgradeCheck.isolated.tsx +321 -0
- package/src/isolated/useAccountSecurity.isolated.ts +1089 -0
- package/src/isolated/useAccountSecurity.native.isolated.ts +61 -0
- package/src/isolated/useLoginController.isolated.ts +1384 -0
- package/src/mutations/entityIds.test.ts +55 -0
- package/src/mutations/entityIds.ts +50 -0
- package/src/persisters/defaultPersisterFactory.native.ts +7 -1
- package/src/persisters/encryptedIndexedDbPersister.ts +3 -0
- package/src/persisters/types.ts +6 -0
- package/src/query/queryWindows.ts +2 -2
- package/src/react/apiHooks.test.tsx +473 -0
- package/src/react/apiHooks.tsx +336 -0
- package/src/react/index.ts +2 -0
- package/src/react/provider.tsx +3 -0
- package/src/react/useSocketEvent.test.tsx +96 -0
- package/src/react/useSocketEvent.ts +59 -0
- package/src/sync/replayCoordinator.ts +5 -4
- package/src/sync/socketTransport.test.ts +49 -0
- package/src/sync/socketTransport.ts +15 -0
- package/src/sync/transport.ts +25 -0
- package/src/testing/fakeTransport.test.ts +18 -0
- package/src/testing/fakeTransport.ts +36 -5
- package/src/types.ts +9 -0
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolated tests for useAccountSecurity, with a fake Better Auth client at the network boundary.
|
|
3
|
+
* The hook imports betterAuthClient.ts (for the bearer-mode link handoff), whose Expo plugin
|
|
4
|
+
* loads native modules, so the Expo plugin is replaced here, where the mock cannot leak into
|
|
5
|
+
* other suites.
|
|
6
|
+
*/
|
|
7
|
+
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
8
|
+
import { act, renderHook, waitFor } from "@testing-library/react-native";
|
|
9
|
+
mock.module("../auth/platform", () => ({ IsWeb: true }));
|
|
10
|
+
mock.module("@better-auth/expo/client", () => ({
|
|
11
|
+
expoClient: () => ({ id: "expo", name: "expo-plugin" }),
|
|
12
|
+
}));
|
|
13
|
+
const { LAST_SIGN_IN_METHOD_MESSAGE, NO_PASSWORD_YET_MESSAGE, SIGN_IN_AGAIN_MESSAGE, getLinkErrorMessage, useAccountSecurity, } = await import("../auth/useAccountSecurity");
|
|
14
|
+
const { createBetterAuthClient } = await import("../auth/betterAuthClient");
|
|
15
|
+
const METHODS = {
|
|
16
|
+
accountLinking: { mode: "verified-email" },
|
|
17
|
+
emailPassword: true,
|
|
18
|
+
multiSession: false,
|
|
19
|
+
passkey: true,
|
|
20
|
+
providers: ["github", "google"],
|
|
21
|
+
signUp: true,
|
|
22
|
+
twoFactor: true,
|
|
23
|
+
};
|
|
24
|
+
const CREATED = new Date("2026-01-02T03:04:05Z");
|
|
25
|
+
const GOOGLE = {
|
|
26
|
+
accountId: "google-sub",
|
|
27
|
+
createdAt: CREATED,
|
|
28
|
+
id: "acc-google",
|
|
29
|
+
providerId: "google",
|
|
30
|
+
};
|
|
31
|
+
const CREDENTIAL = {
|
|
32
|
+
accountId: "u1",
|
|
33
|
+
createdAt: CREATED,
|
|
34
|
+
id: "acc-credential",
|
|
35
|
+
providerId: "credential",
|
|
36
|
+
};
|
|
37
|
+
const CURRENT = { id: "s-current", token: "tok-current", userAgent: "Firefox" };
|
|
38
|
+
const OTHER = { id: "s-other", token: "tok-other", userAgent: "Safari" };
|
|
39
|
+
const PASSKEY = { createdAt: CREATED, id: "pk-1", name: "Laptop" };
|
|
40
|
+
const ok = (data) => ({ data, error: null });
|
|
41
|
+
// A fake Better Auth client at the network boundary: each call records its arguments and answers
|
|
42
|
+
// from `state` the way the real client resolves `{data, error}`.
|
|
43
|
+
const fakeClient = (initial = {}, overrides = {}) => {
|
|
44
|
+
const state = {
|
|
45
|
+
accounts: [GOOGLE, CREDENTIAL],
|
|
46
|
+
methods: METHODS,
|
|
47
|
+
passkeys: [PASSKEY],
|
|
48
|
+
sessionId: CURRENT.id,
|
|
49
|
+
sessions: [CURRENT, OTHER],
|
|
50
|
+
user: { email: "jane@example.com", id: "u1", twoFactorEnabled: false },
|
|
51
|
+
...initial,
|
|
52
|
+
};
|
|
53
|
+
const calls = {};
|
|
54
|
+
const record = (name, arg) => {
|
|
55
|
+
calls[name] = [...(calls[name] ?? []), arg];
|
|
56
|
+
return overrides.fail?.[name];
|
|
57
|
+
};
|
|
58
|
+
const client = {
|
|
59
|
+
$fetch: async (path, options) => {
|
|
60
|
+
const failure = record(`$fetch ${path}`, options);
|
|
61
|
+
if (failure) {
|
|
62
|
+
return { data: null, error: failure.error };
|
|
63
|
+
}
|
|
64
|
+
if (path === "/terreno/methods") {
|
|
65
|
+
return { data: state.methods, error: null };
|
|
66
|
+
}
|
|
67
|
+
if (path === "/terreno/set-password") {
|
|
68
|
+
state.accounts = state.accounts.some((account) => account.providerId === "credential")
|
|
69
|
+
? state.accounts
|
|
70
|
+
: [...state.accounts, CREDENTIAL];
|
|
71
|
+
return { data: { status: true }, error: null };
|
|
72
|
+
}
|
|
73
|
+
return { data: null, error: { message: "Not found", status: 404 } };
|
|
74
|
+
},
|
|
75
|
+
calls,
|
|
76
|
+
changePassword: async (body) => {
|
|
77
|
+
const failure = record("changePassword", body);
|
|
78
|
+
if (failure) {
|
|
79
|
+
return failure;
|
|
80
|
+
}
|
|
81
|
+
if (body.revokeOtherSessions) {
|
|
82
|
+
state.sessionId = "s-new";
|
|
83
|
+
state.sessions = [{ id: "s-new", token: "tok-new" }];
|
|
84
|
+
}
|
|
85
|
+
return ok({ token: null });
|
|
86
|
+
},
|
|
87
|
+
getSession: async (options) => {
|
|
88
|
+
const failure = record("getSession", options);
|
|
89
|
+
if (failure) {
|
|
90
|
+
return failure;
|
|
91
|
+
}
|
|
92
|
+
if (!state.user) {
|
|
93
|
+
return ok(null);
|
|
94
|
+
}
|
|
95
|
+
return ok({ session: { id: state.sessionId }, user: state.user });
|
|
96
|
+
},
|
|
97
|
+
linkSocial: async (body) => {
|
|
98
|
+
record("linkSocial", body);
|
|
99
|
+
const failure = overrides.fail?.linkSocial;
|
|
100
|
+
if (failure?.error) {
|
|
101
|
+
return { error: { ...failure.error, status: failure.error.status ?? 400 } };
|
|
102
|
+
}
|
|
103
|
+
state.accounts = [...state.accounts, { id: `acc-${body.provider}`, providerId: body.provider }];
|
|
104
|
+
return { error: null };
|
|
105
|
+
},
|
|
106
|
+
listAccounts: async () => {
|
|
107
|
+
return record("listAccounts") ?? ok(state.accounts);
|
|
108
|
+
},
|
|
109
|
+
listSessions: async () => {
|
|
110
|
+
return record("listSessions") ?? ok(state.sessions);
|
|
111
|
+
},
|
|
112
|
+
revokeOtherSessions: async () => {
|
|
113
|
+
const failure = record("revokeOtherSessions");
|
|
114
|
+
if (failure) {
|
|
115
|
+
return failure;
|
|
116
|
+
}
|
|
117
|
+
state.sessions = state.sessions.filter((session) => session.id === state.sessionId);
|
|
118
|
+
return ok({ status: true });
|
|
119
|
+
},
|
|
120
|
+
revokeSession: async (body) => {
|
|
121
|
+
const failure = record("revokeSession", body);
|
|
122
|
+
if (failure) {
|
|
123
|
+
return failure;
|
|
124
|
+
}
|
|
125
|
+
state.sessions = state.sessions.filter((session) => session.token !== body.token);
|
|
126
|
+
return ok({ status: true });
|
|
127
|
+
},
|
|
128
|
+
state,
|
|
129
|
+
unlinkAccount: async (body) => {
|
|
130
|
+
const failure = record("unlinkAccount", body);
|
|
131
|
+
if (failure) {
|
|
132
|
+
return failure;
|
|
133
|
+
}
|
|
134
|
+
state.accounts = state.accounts.filter((account) => account.id !== body.accountId);
|
|
135
|
+
return ok({ status: true });
|
|
136
|
+
},
|
|
137
|
+
...(overrides.withoutPasskey
|
|
138
|
+
? {}
|
|
139
|
+
: {
|
|
140
|
+
passkey: {
|
|
141
|
+
addPasskey: async (options) => {
|
|
142
|
+
const failure = record("addPasskey", options);
|
|
143
|
+
if (failure) {
|
|
144
|
+
return failure;
|
|
145
|
+
}
|
|
146
|
+
state.passkeys = [...state.passkeys, { id: "pk-2", name: options?.name }];
|
|
147
|
+
return ok({});
|
|
148
|
+
},
|
|
149
|
+
deletePasskey: async (body) => {
|
|
150
|
+
const failure = record("deletePasskey", body);
|
|
151
|
+
if (failure) {
|
|
152
|
+
return failure;
|
|
153
|
+
}
|
|
154
|
+
state.passkeys = state.passkeys.filter((passkey) => passkey.id !== body.id);
|
|
155
|
+
return ok({ status: true });
|
|
156
|
+
},
|
|
157
|
+
listUserPasskeys: async () => {
|
|
158
|
+
return record("listUserPasskeys") ?? ok(state.passkeys);
|
|
159
|
+
},
|
|
160
|
+
updatePasskey: async (body) => {
|
|
161
|
+
const failure = record("updatePasskey", body);
|
|
162
|
+
if (failure) {
|
|
163
|
+
return failure;
|
|
164
|
+
}
|
|
165
|
+
state.passkeys = state.passkeys.map((passkey) => passkey.id === body.id ? { ...passkey, name: body.name } : passkey);
|
|
166
|
+
return ok({});
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
...(overrides.withoutTwoFactor
|
|
171
|
+
? {}
|
|
172
|
+
: {
|
|
173
|
+
twoFactor: {
|
|
174
|
+
disable: async (body) => {
|
|
175
|
+
const failure = record("disable", body);
|
|
176
|
+
if (failure) {
|
|
177
|
+
return failure;
|
|
178
|
+
}
|
|
179
|
+
state.user = state.user ? { ...state.user, twoFactorEnabled: false } : null;
|
|
180
|
+
state.sessionId = "s-after-disable";
|
|
181
|
+
return ok({ status: true });
|
|
182
|
+
},
|
|
183
|
+
enable: async (body) => {
|
|
184
|
+
const failure = record("enable", body);
|
|
185
|
+
if (failure) {
|
|
186
|
+
return failure;
|
|
187
|
+
}
|
|
188
|
+
return ok(overrides.enableData ?? {
|
|
189
|
+
backupCodes: ["code-1", "code-2"],
|
|
190
|
+
totpURI: "otpauth://totp/Terreno:jane?secret=ABC",
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
generateBackupCodes: async (body) => {
|
|
194
|
+
const failure = record("generateBackupCodes", body);
|
|
195
|
+
if (failure) {
|
|
196
|
+
return failure;
|
|
197
|
+
}
|
|
198
|
+
return ok({ backupCodes: ["new-1", "new-2"], status: true });
|
|
199
|
+
},
|
|
200
|
+
verifyTotp: async (body) => {
|
|
201
|
+
const failure = record("verifyTotp", body);
|
|
202
|
+
if (failure) {
|
|
203
|
+
return failure;
|
|
204
|
+
}
|
|
205
|
+
state.user = state.user ? { ...state.user, twoFactorEnabled: true } : null;
|
|
206
|
+
state.sessionId = "s-after-verify";
|
|
207
|
+
return ok({ token: "tok-after-verify" });
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
}),
|
|
211
|
+
};
|
|
212
|
+
return client;
|
|
213
|
+
};
|
|
214
|
+
const countOf = (client, name) => client.calls[name]?.length ?? 0;
|
|
215
|
+
/** How many times each section has loaded. */
|
|
216
|
+
const loadCounts = (client) => ({
|
|
217
|
+
accounts: countOf(client, "listAccounts"),
|
|
218
|
+
passkeys: countOf(client, "listUserPasskeys"),
|
|
219
|
+
session: countOf(client, "getSession"),
|
|
220
|
+
sessions: countOf(client, "listSessions"),
|
|
221
|
+
});
|
|
222
|
+
const renderSecurity = (client, options = {}) => {
|
|
223
|
+
return renderHook(() => useAccountSecurity({ callbackURL: "/security", client, passkeySupported: true, ...options }));
|
|
224
|
+
};
|
|
225
|
+
const waitForLoaded = async (result) => {
|
|
226
|
+
await waitFor(() => expect(result.current.screenProps.isLoading).toBe(false));
|
|
227
|
+
};
|
|
228
|
+
const linkedAccountsOf = (result) => {
|
|
229
|
+
const props = result.current.screenProps.linkedAccounts;
|
|
230
|
+
if (!props) {
|
|
231
|
+
throw new Error("linkedAccounts is hidden");
|
|
232
|
+
}
|
|
233
|
+
return props;
|
|
234
|
+
};
|
|
235
|
+
const globalWithWindow = globalThis;
|
|
236
|
+
describe("useAccountSecurity", () => {
|
|
237
|
+
afterEach(() => {
|
|
238
|
+
delete globalWithWindow.window;
|
|
239
|
+
});
|
|
240
|
+
it("loads every section and builds each card's props", async () => {
|
|
241
|
+
const client = fakeClient();
|
|
242
|
+
const { result } = renderSecurity(client);
|
|
243
|
+
expect(result.current.screenProps.isLoading).toBe(true);
|
|
244
|
+
await waitForLoaded(result);
|
|
245
|
+
const { screenProps } = result.current;
|
|
246
|
+
expect(screenProps.error).toBeUndefined();
|
|
247
|
+
expect(screenProps.linkedAccounts?.accounts).toEqual([
|
|
248
|
+
{ accountId: "google-sub", id: "acc-google", linkedAt: CREATED, providerId: "google" },
|
|
249
|
+
{ accountId: "u1", id: "acc-credential", linkedAt: CREATED, providerId: "credential" },
|
|
250
|
+
]);
|
|
251
|
+
expect(screenProps.linkedAccounts?.providers).toEqual([{ id: "github" }, { id: "google" }]);
|
|
252
|
+
expect(screenProps.password?.hasPassword).toBe(true);
|
|
253
|
+
expect(screenProps.passkeys?.passkeys).toEqual([PASSKEY]);
|
|
254
|
+
expect(screenProps.passkeys?.supported).toBe(true);
|
|
255
|
+
expect(screenProps.twoFactor?.enabled).toBe(false);
|
|
256
|
+
expect(screenProps.twoFactor?.hasPassword).toBe(true);
|
|
257
|
+
// Password managers pair the password forms with the signed-in account.
|
|
258
|
+
expect(screenProps.password?.username).toBe("jane@example.com");
|
|
259
|
+
expect(screenProps.twoFactor?.username).toBe("jane@example.com");
|
|
260
|
+
expect(screenProps.sessions?.sessions).toEqual([CURRENT, OTHER]);
|
|
261
|
+
expect(screenProps.sessions?.currentSessionId).toBe("s-current");
|
|
262
|
+
expect(result.current.user?.email).toBe("jane@example.com");
|
|
263
|
+
// The session is read past the cookie cache, so a 2FA change shows at once.
|
|
264
|
+
expect(client.calls.getSession).toEqual([{ query: { disableCookieCache: true } }]);
|
|
265
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 1, sessions: 1 });
|
|
266
|
+
});
|
|
267
|
+
it("shows only the cards the server's methods turn on", async () => {
|
|
268
|
+
const client = fakeClient({
|
|
269
|
+
methods: {
|
|
270
|
+
...METHODS,
|
|
271
|
+
emailPassword: false,
|
|
272
|
+
passkey: false,
|
|
273
|
+
providers: [],
|
|
274
|
+
twoFactor: false,
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
const { result } = renderSecurity(client);
|
|
278
|
+
await waitForLoaded(result);
|
|
279
|
+
expect(result.current.screenProps.linkedAccounts).toBeUndefined();
|
|
280
|
+
expect(result.current.screenProps.password).toBeUndefined();
|
|
281
|
+
expect(result.current.screenProps.passkeys).toBeUndefined();
|
|
282
|
+
expect(result.current.screenProps.twoFactor).toBeUndefined();
|
|
283
|
+
expect(result.current.screenProps.sessions).toBeDefined();
|
|
284
|
+
expect(countOf(client, "listUserPasskeys")).toBe(0);
|
|
285
|
+
});
|
|
286
|
+
it("hides the passkey and two-factor cards when the client lacks those features", async () => {
|
|
287
|
+
const client = fakeClient({}, { withoutPasskey: true, withoutTwoFactor: true });
|
|
288
|
+
const { result } = renderSecurity(client);
|
|
289
|
+
await waitForLoaded(result);
|
|
290
|
+
expect(result.current.screenProps.passkeys).toBeUndefined();
|
|
291
|
+
expect(result.current.screenProps.twoFactor).toBeUndefined();
|
|
292
|
+
});
|
|
293
|
+
it("uses methods the app passes instead of requesting them", async () => {
|
|
294
|
+
const client = fakeClient();
|
|
295
|
+
const { result } = renderSecurity(client, { methods: { ...METHODS, providers: ["github"] } });
|
|
296
|
+
await waitForLoaded(result);
|
|
297
|
+
expect(countOf(client, "$fetch /terreno/methods")).toBe(0);
|
|
298
|
+
expect(linkedAccountsOf(result).providers).toEqual([{ id: "github" }]);
|
|
299
|
+
});
|
|
300
|
+
it("labels providers and offers no Link button when linking is off", async () => {
|
|
301
|
+
const client = fakeClient({
|
|
302
|
+
methods: { ...METHODS, accountLinking: { mode: "never" }, providers: ["mock-oidc"] },
|
|
303
|
+
});
|
|
304
|
+
const { result } = renderSecurity(client, { providerLabels: { "mock-oidc": "Mock OIDC" } });
|
|
305
|
+
await waitForLoaded(result);
|
|
306
|
+
expect(linkedAccountsOf(result).providers).toEqual([{ id: "mock-oidc", label: "Mock OIDC" }]);
|
|
307
|
+
expect(linkedAccountsOf(result).onLink).toBeUndefined();
|
|
308
|
+
expect(linkedAccountsOf(result).onUnlink).toBeDefined();
|
|
309
|
+
});
|
|
310
|
+
it("leaves a provider unlabelled when its id matches an Object.prototype key", async () => {
|
|
311
|
+
const client = fakeClient({ methods: { ...METHODS, providers: ["__proto__", "constructor"] } });
|
|
312
|
+
const { result } = renderSecurity(client, { providerLabels: { "mock-oidc": "Mock OIDC" } });
|
|
313
|
+
await waitForLoaded(result);
|
|
314
|
+
expect(linkedAccountsOf(result).providers).toEqual([{ id: "__proto__" }, { id: "constructor" }]);
|
|
315
|
+
});
|
|
316
|
+
describe("linked accounts", () => {
|
|
317
|
+
it("never calls the client to unlink the last sign-in method", async () => {
|
|
318
|
+
const client = fakeClient({ accounts: [GOOGLE], passkeys: [PASSKEY] });
|
|
319
|
+
const { result } = renderSecurity(client);
|
|
320
|
+
await waitForLoaded(result);
|
|
321
|
+
const google = linkedAccountsOf(result).accounts[0];
|
|
322
|
+
await expect(linkedAccountsOf(result).onUnlink?.("google", google)).rejects.toThrow(LAST_SIGN_IN_METHOD_MESSAGE);
|
|
323
|
+
expect(countOf(client, "unlinkAccount")).toBe(0);
|
|
324
|
+
expect(countOf(client, "listAccounts")).toBe(1);
|
|
325
|
+
});
|
|
326
|
+
it("unlinks by the Better Auth account id and refetches only the accounts", async () => {
|
|
327
|
+
const client = fakeClient({
|
|
328
|
+
accounts: [GOOGLE, { id: "acc-github", providerId: "github" }, CREDENTIAL],
|
|
329
|
+
});
|
|
330
|
+
const { result } = renderSecurity(client);
|
|
331
|
+
await waitForLoaded(result);
|
|
332
|
+
const github = linkedAccountsOf(result).accounts[1];
|
|
333
|
+
await act(async () => {
|
|
334
|
+
await linkedAccountsOf(result).onUnlink?.("github", github);
|
|
335
|
+
});
|
|
336
|
+
expect(client.calls.unlinkAccount).toEqual([{ accountId: "acc-github" }]);
|
|
337
|
+
expect(loadCounts(client)).toEqual({ accounts: 2, passkeys: 1, session: 1, sessions: 1 });
|
|
338
|
+
expect(linkedAccountsOf(result).accounts.map((account) => account.providerId)).toEqual([
|
|
339
|
+
"google",
|
|
340
|
+
"credential",
|
|
341
|
+
]);
|
|
342
|
+
});
|
|
343
|
+
it("throws the server's message, or a fallback, when unlinking fails", async () => {
|
|
344
|
+
const failing = fakeClient({}, { fail: { unlinkAccount: { error: { code: "X", message: "Nope", status: 400 } } } });
|
|
345
|
+
const { result } = renderSecurity(failing);
|
|
346
|
+
await waitForLoaded(result);
|
|
347
|
+
const google = linkedAccountsOf(result).accounts[0];
|
|
348
|
+
await expect(linkedAccountsOf(result).onUnlink?.("google", google)).rejects.toThrow("Nope");
|
|
349
|
+
expect(countOf(failing, "listAccounts")).toBe(1);
|
|
350
|
+
const silent = fakeClient({}, { fail: { unlinkAccount: { error: { status: 500 } } } });
|
|
351
|
+
const second = renderSecurity(silent);
|
|
352
|
+
await waitForLoaded(second.result);
|
|
353
|
+
const account = linkedAccountsOf(second.result).accounts[0];
|
|
354
|
+
await expect(linkedAccountsOf(second.result).onUnlink?.("google", account)).rejects.toThrow("Couldn't unlink that account.");
|
|
355
|
+
});
|
|
356
|
+
it("links through linkSocial in cookie mode, then refetches the accounts", async () => {
|
|
357
|
+
const client = fakeClient();
|
|
358
|
+
const { result } = renderSecurity(client, { errorCallbackURL: "/security?failed=1" });
|
|
359
|
+
await waitForLoaded(result);
|
|
360
|
+
await act(async () => {
|
|
361
|
+
await linkedAccountsOf(result).onLink?.("github");
|
|
362
|
+
});
|
|
363
|
+
expect(client.calls.linkSocial).toEqual([
|
|
364
|
+
{ callbackURL: "/security", errorCallbackURL: "/security?failed=1", provider: "github" },
|
|
365
|
+
]);
|
|
366
|
+
expect(countOf(client, "listAccounts")).toBe(2);
|
|
367
|
+
expect(linkedAccountsOf(result).accounts.map((account) => account.providerId)).toContain("github");
|
|
368
|
+
});
|
|
369
|
+
it("explains a refused link", async () => {
|
|
370
|
+
const client = fakeClient({}, { fail: { linkSocial: { error: { code: "LINKING_DISABLED", message: "Off", status: 403 } } } });
|
|
371
|
+
const { result } = renderSecurity(client);
|
|
372
|
+
await waitForLoaded(result);
|
|
373
|
+
await expect(linkedAccountsOf(result).onLink?.("github")).rejects.toThrow("This app does not link sign-in methods.");
|
|
374
|
+
expect(countOf(client, "listAccounts")).toBe(1);
|
|
375
|
+
});
|
|
376
|
+
it("links through the OAuth handoff in bearer mode", async () => {
|
|
377
|
+
const submitted = [];
|
|
378
|
+
const form = {
|
|
379
|
+
action: "",
|
|
380
|
+
appendChild: (field) => {
|
|
381
|
+
form.token = field.value;
|
|
382
|
+
},
|
|
383
|
+
method: "",
|
|
384
|
+
style: { display: "" },
|
|
385
|
+
submit: () => {
|
|
386
|
+
submitted.push({ action: form.action, method: form.method, token: form.token });
|
|
387
|
+
},
|
|
388
|
+
token: "",
|
|
389
|
+
};
|
|
390
|
+
const storage = new Map();
|
|
391
|
+
const memoryStorage = {
|
|
392
|
+
getItem: (key) => storage.get(key) ?? null,
|
|
393
|
+
removeItem: (key) => {
|
|
394
|
+
storage.delete(key);
|
|
395
|
+
},
|
|
396
|
+
setItem: (key, value) => {
|
|
397
|
+
storage.set(key, value);
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
globalWithWindow.window = {
|
|
401
|
+
document: {
|
|
402
|
+
body: { appendChild: () => { } },
|
|
403
|
+
createElement: (tag) => tag === "form" ? form : { name: "", type: "", value: "" },
|
|
404
|
+
},
|
|
405
|
+
localStorage: memoryStorage,
|
|
406
|
+
location: { href: "http://app.test/security" },
|
|
407
|
+
sessionStorage: memoryStorage,
|
|
408
|
+
};
|
|
409
|
+
const requests = [];
|
|
410
|
+
const originalFetch = globalThis.fetch;
|
|
411
|
+
globalThis.fetch = (async (input, init) => {
|
|
412
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
413
|
+
const body = input instanceof Request ? await input.text() : init?.body;
|
|
414
|
+
requests.push({ body: body ? JSON.parse(String(body)) : undefined, url });
|
|
415
|
+
if (url.includes("/oauth-handoff/link-intent")) {
|
|
416
|
+
return Response.json({
|
|
417
|
+
startURL: "http://api.test/api/auth/oauth-handoff/link-start",
|
|
418
|
+
token: "link-token",
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return Response.json(null);
|
|
422
|
+
});
|
|
423
|
+
try {
|
|
424
|
+
const realClient = createBetterAuthClient({
|
|
425
|
+
baseURL: "http://api.test",
|
|
426
|
+
features: { passkey: true, twoFactor: true },
|
|
427
|
+
scheme: "terreno",
|
|
428
|
+
webAuth: "bearer",
|
|
429
|
+
});
|
|
430
|
+
// The real client's loads all answer null; the methods are passed in.
|
|
431
|
+
const { result } = renderHook(() => useAccountSecurity({ callbackURL: "/security", client: realClient, methods: METHODS }));
|
|
432
|
+
await waitForLoaded(result);
|
|
433
|
+
// Linking is driven from the real client so its bearer config applies.
|
|
434
|
+
await act(async () => {
|
|
435
|
+
await result.current.screenProps.linkedAccounts?.onLink?.("github");
|
|
436
|
+
});
|
|
437
|
+
const intent = requests.find((request) => request.url.includes("link-intent"));
|
|
438
|
+
expect(intent?.body).toEqual({
|
|
439
|
+
callbackURL: "http://app.test/security",
|
|
440
|
+
errorCallbackURL: "http://app.test/security",
|
|
441
|
+
provider: "github",
|
|
442
|
+
});
|
|
443
|
+
expect(submitted).toEqual([
|
|
444
|
+
{
|
|
445
|
+
action: "http://api.test/api/auth/oauth-handoff/link-start",
|
|
446
|
+
method: "POST",
|
|
447
|
+
token: "link-token",
|
|
448
|
+
},
|
|
449
|
+
]);
|
|
450
|
+
}
|
|
451
|
+
finally {
|
|
452
|
+
globalThis.fetch = originalFetch;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
it("turns a link's ?error= return into a readable card error", async () => {
|
|
456
|
+
const client = fakeClient();
|
|
457
|
+
const { result } = renderSecurity(client, {
|
|
458
|
+
linkError: "account_already_linked_to_different_user",
|
|
459
|
+
});
|
|
460
|
+
await waitForLoaded(result);
|
|
461
|
+
expect(linkedAccountsOf(result).error).toBe("That account is already linked to another user.");
|
|
462
|
+
expect(getLinkErrorMessage(["<script>"])).toBe("Couldn't link that account. Please try again.");
|
|
463
|
+
expect(getLinkErrorMessage(null)).toBeUndefined();
|
|
464
|
+
});
|
|
465
|
+
it("shows the generic link error for a ?error= that matches an Object.prototype key", async () => {
|
|
466
|
+
for (const code of ["__proto__", "constructor"]) {
|
|
467
|
+
expect(getLinkErrorMessage(code)).toBe("Couldn't link that account. Please try again.");
|
|
468
|
+
}
|
|
469
|
+
const client = fakeClient();
|
|
470
|
+
const { result } = renderSecurity(client, { linkError: "__proto__" });
|
|
471
|
+
await waitForLoaded(result);
|
|
472
|
+
expect(linkedAccountsOf(result).error).toBe("Couldn't link that account. Please try again.");
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
describe("password", () => {
|
|
476
|
+
it("sets a first password for an OAuth-only user through the Terreno endpoint", async () => {
|
|
477
|
+
const client = fakeClient({ accounts: [GOOGLE] });
|
|
478
|
+
const { result } = renderSecurity(client);
|
|
479
|
+
await waitForLoaded(result);
|
|
480
|
+
expect(result.current.screenProps.password?.hasPassword).toBe(false);
|
|
481
|
+
expect(result.current.screenProps.twoFactor?.hasPassword).toBe(false);
|
|
482
|
+
await act(async () => {
|
|
483
|
+
await result.current.screenProps.password?.onSubmit({
|
|
484
|
+
mode: "set",
|
|
485
|
+
newPassword: "first-password-1",
|
|
486
|
+
revokeOtherSessions: false,
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
expect(client.calls["$fetch /terreno/set-password"]).toEqual([
|
|
490
|
+
{ body: { newPassword: "first-password-1" }, method: "POST" },
|
|
491
|
+
]);
|
|
492
|
+
expect(countOf(client, "changePassword")).toBe(0);
|
|
493
|
+
expect(loadCounts(client)).toEqual({ accounts: 2, passkeys: 1, session: 1, sessions: 1 });
|
|
494
|
+
expect(result.current.screenProps.password?.hasPassword).toBe(true);
|
|
495
|
+
});
|
|
496
|
+
it("shows the set-password endpoint's refusal", async () => {
|
|
497
|
+
const client = fakeClient({ accounts: [GOOGLE] }, {
|
|
498
|
+
fail: {
|
|
499
|
+
"$fetch /terreno/set-password": {
|
|
500
|
+
error: { code: "PASSWORD_ALREADY_SET", message: "User already has a password set" },
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
const { result } = renderSecurity(client);
|
|
505
|
+
await waitForLoaded(result);
|
|
506
|
+
await expect(result.current.screenProps.password?.onSubmit({
|
|
507
|
+
mode: "set",
|
|
508
|
+
newPassword: "first-password-1",
|
|
509
|
+
revokeOtherSessions: false,
|
|
510
|
+
})).rejects.toThrow("User already has a password set");
|
|
511
|
+
});
|
|
512
|
+
it("changes the password and reloads the sessions it signed out", async () => {
|
|
513
|
+
const client = fakeClient();
|
|
514
|
+
const { result } = renderSecurity(client, { minPasswordLength: 12 });
|
|
515
|
+
await waitForLoaded(result);
|
|
516
|
+
expect(result.current.screenProps.password?.minLength).toBe(12);
|
|
517
|
+
await act(async () => {
|
|
518
|
+
await result.current.screenProps.password?.onSubmit({
|
|
519
|
+
currentPassword: "old-password",
|
|
520
|
+
mode: "change",
|
|
521
|
+
newPassword: "new-password-1",
|
|
522
|
+
revokeOtherSessions: false,
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 1, sessions: 1 });
|
|
526
|
+
await act(async () => {
|
|
527
|
+
await result.current.screenProps.password?.onSubmit({
|
|
528
|
+
currentPassword: "new-password-1",
|
|
529
|
+
mode: "change",
|
|
530
|
+
newPassword: "newer-password-1",
|
|
531
|
+
revokeOtherSessions: true,
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
expect(client.calls.changePassword).toEqual([
|
|
535
|
+
{
|
|
536
|
+
currentPassword: "old-password",
|
|
537
|
+
newPassword: "new-password-1",
|
|
538
|
+
revokeOtherSessions: false,
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
currentPassword: "new-password-1",
|
|
542
|
+
newPassword: "newer-password-1",
|
|
543
|
+
revokeOtherSessions: true,
|
|
544
|
+
},
|
|
545
|
+
]);
|
|
546
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 2, sessions: 2 });
|
|
547
|
+
expect(result.current.screenProps.sessions?.currentSessionId).toBe("s-new");
|
|
548
|
+
});
|
|
549
|
+
it("switches to set mode when the credential row has no password", async () => {
|
|
550
|
+
const client = fakeClient({}, {
|
|
551
|
+
fail: {
|
|
552
|
+
changePassword: {
|
|
553
|
+
error: {
|
|
554
|
+
code: "CREDENTIAL_ACCOUNT_NOT_FOUND",
|
|
555
|
+
message: "Credential account not found",
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
});
|
|
560
|
+
const { result } = renderSecurity(client);
|
|
561
|
+
await waitForLoaded(result);
|
|
562
|
+
expect(result.current.screenProps.password?.hasPassword).toBe(true);
|
|
563
|
+
await act(async () => {
|
|
564
|
+
await expect(result.current.screenProps.password?.onSubmit({
|
|
565
|
+
currentPassword: "anything",
|
|
566
|
+
mode: "change",
|
|
567
|
+
newPassword: "new-password-1",
|
|
568
|
+
revokeOtherSessions: false,
|
|
569
|
+
})).rejects.toThrow(NO_PASSWORD_YET_MESSAGE);
|
|
570
|
+
});
|
|
571
|
+
expect(result.current.screenProps.password?.hasPassword).toBe(false);
|
|
572
|
+
expect(result.current.screenProps.twoFactor?.hasPassword).toBe(false);
|
|
573
|
+
await act(async () => {
|
|
574
|
+
await result.current.screenProps.password?.onSubmit({
|
|
575
|
+
mode: "set",
|
|
576
|
+
newPassword: "first-password-1",
|
|
577
|
+
revokeOtherSessions: false,
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
expect(client.calls["$fetch /terreno/set-password"]).toHaveLength(1);
|
|
581
|
+
expect(result.current.screenProps.password?.hasPassword).toBe(true);
|
|
582
|
+
});
|
|
583
|
+
it("throws Better Auth's message for a wrong current password", async () => {
|
|
584
|
+
const client = fakeClient({}, { fail: { changePassword: { error: { code: "INVALID_PASSWORD", message: "Invalid password" } } } });
|
|
585
|
+
const { result } = renderSecurity(client);
|
|
586
|
+
await waitForLoaded(result);
|
|
587
|
+
await expect(result.current.screenProps.password?.onSubmit({
|
|
588
|
+
currentPassword: "wrong",
|
|
589
|
+
mode: "change",
|
|
590
|
+
newPassword: "new-password-1",
|
|
591
|
+
revokeOtherSessions: false,
|
|
592
|
+
})).rejects.toThrow("Invalid password");
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
describe("passkeys", () => {
|
|
596
|
+
it("adds, renames and removes passkeys, refetching only the passkeys", async () => {
|
|
597
|
+
const client = fakeClient();
|
|
598
|
+
const { result } = renderSecurity(client);
|
|
599
|
+
await waitForLoaded(result);
|
|
600
|
+
await act(async () => {
|
|
601
|
+
await result.current.screenProps.passkeys?.onAdd?.("Phone");
|
|
602
|
+
});
|
|
603
|
+
await act(async () => {
|
|
604
|
+
await result.current.screenProps.passkeys?.onRename?.("pk-1", "Work laptop");
|
|
605
|
+
});
|
|
606
|
+
await act(async () => {
|
|
607
|
+
await result.current.screenProps.passkeys?.onRemove?.(PASSKEY);
|
|
608
|
+
});
|
|
609
|
+
expect(client.calls.addPasskey).toEqual([{ name: "Phone" }]);
|
|
610
|
+
expect(client.calls.updatePasskey).toEqual([{ id: "pk-1", name: "Work laptop" }]);
|
|
611
|
+
expect(client.calls.deletePasskey).toEqual([{ id: "pk-1" }]);
|
|
612
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 4, session: 1, sessions: 1 });
|
|
613
|
+
expect(result.current.screenProps.passkeys?.passkeys).toEqual([{ id: "pk-2", name: "Phone" }]);
|
|
614
|
+
});
|
|
615
|
+
it("adds an unnamed passkey without a name", async () => {
|
|
616
|
+
const client = fakeClient();
|
|
617
|
+
const { result } = renderSecurity(client);
|
|
618
|
+
await waitForLoaded(result);
|
|
619
|
+
await act(async () => {
|
|
620
|
+
await result.current.screenProps.passkeys?.onAdd?.();
|
|
621
|
+
});
|
|
622
|
+
expect(client.calls.addPasskey).toEqual([undefined]);
|
|
623
|
+
});
|
|
624
|
+
it("never removes the last sign-in method", async () => {
|
|
625
|
+
const client = fakeClient({ accounts: [], passkeys: [PASSKEY] });
|
|
626
|
+
const { result } = renderSecurity(client);
|
|
627
|
+
await waitForLoaded(result);
|
|
628
|
+
await expect(result.current.screenProps.passkeys?.onRemove?.(PASSKEY)).rejects.toThrow(LAST_SIGN_IN_METHOD_MESSAGE);
|
|
629
|
+
expect(countOf(client, "deletePasskey")).toBe(0);
|
|
630
|
+
});
|
|
631
|
+
it("throws when adding a passkey fails, such as a cancelled prompt", async () => {
|
|
632
|
+
const client = fakeClient({}, { fail: { addPasskey: { error: { message: "Registration cancelled", status: 400 } } } });
|
|
633
|
+
const { result } = renderSecurity(client);
|
|
634
|
+
await waitForLoaded(result);
|
|
635
|
+
await expect(result.current.screenProps.passkeys?.onAdd?.("Phone")).rejects.toThrow("Registration cancelled");
|
|
636
|
+
expect(countOf(client, "listUserPasskeys")).toBe(1);
|
|
637
|
+
});
|
|
638
|
+
it("reports WebAuthn support from the browser", async () => {
|
|
639
|
+
globalWithWindow.window = { PublicKeyCredential: () => { } };
|
|
640
|
+
const client = fakeClient();
|
|
641
|
+
const { result } = renderSecurity(client, { passkeySupported: undefined });
|
|
642
|
+
await waitForLoaded(result);
|
|
643
|
+
expect(result.current.screenProps.passkeys?.supported).toBe(true);
|
|
644
|
+
delete globalWithWindow.window;
|
|
645
|
+
const other = renderSecurity(fakeClient(), { passkeySupported: undefined });
|
|
646
|
+
await waitForLoaded(other.result);
|
|
647
|
+
expect(other.result.current.screenProps.passkeys?.supported).toBe(false);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
describe("two-factor", () => {
|
|
651
|
+
it("returns the backup codes to the card when enrolling", async () => {
|
|
652
|
+
const client = fakeClient();
|
|
653
|
+
const { result } = renderSecurity(client);
|
|
654
|
+
await waitForLoaded(result);
|
|
655
|
+
let enrollment;
|
|
656
|
+
await act(async () => {
|
|
657
|
+
enrollment = await result.current.screenProps.twoFactor?.onStartEnroll("password-1");
|
|
658
|
+
});
|
|
659
|
+
expect(client.calls.enable).toEqual([{ password: "password-1" }]);
|
|
660
|
+
expect(enrollment).toEqual({
|
|
661
|
+
backupCodes: ["code-1", "code-2"],
|
|
662
|
+
totpURI: "otpauth://totp/Terreno:jane?secret=ABC",
|
|
663
|
+
});
|
|
664
|
+
// Enabling only stores the secret; nothing reloads until the code is verified.
|
|
665
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 1, sessions: 1 });
|
|
666
|
+
});
|
|
667
|
+
it("refuses the OTP branch of enable, which has no authenticator URI", async () => {
|
|
668
|
+
const client = fakeClient({}, { enableData: { method: "otp" } });
|
|
669
|
+
const { result } = renderSecurity(client);
|
|
670
|
+
await waitForLoaded(result);
|
|
671
|
+
await expect(result.current.screenProps.twoFactor?.onStartEnroll()).rejects.toThrow("Couldn't start two-factor setup.");
|
|
672
|
+
expect(client.calls.enable).toEqual([{ password: "" }]);
|
|
673
|
+
});
|
|
674
|
+
it("verifies the code, then reloads the session and sessions it replaced", async () => {
|
|
675
|
+
const client = fakeClient();
|
|
676
|
+
const { result } = renderSecurity(client);
|
|
677
|
+
await waitForLoaded(result);
|
|
678
|
+
await act(async () => {
|
|
679
|
+
await result.current.screenProps.twoFactor?.onVerify("123456");
|
|
680
|
+
});
|
|
681
|
+
expect(client.calls.verifyTotp).toEqual([{ code: "123456" }]);
|
|
682
|
+
expect(result.current.screenProps.twoFactor?.enabled).toBe(true);
|
|
683
|
+
expect(result.current.screenProps.sessions?.currentSessionId).toBe("s-after-verify");
|
|
684
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 2, sessions: 2 });
|
|
685
|
+
});
|
|
686
|
+
it("throws for a wrong code without reloading", async () => {
|
|
687
|
+
const client = fakeClient({}, { fail: { verifyTotp: { error: { code: "INVALID_CODE", message: "Invalid code" } } } });
|
|
688
|
+
const { result } = renderSecurity(client);
|
|
689
|
+
await waitForLoaded(result);
|
|
690
|
+
await expect(result.current.screenProps.twoFactor?.onVerify("000000")).rejects.toThrow("Invalid code");
|
|
691
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 1, sessions: 1 });
|
|
692
|
+
});
|
|
693
|
+
it("creates new backup codes and turns two-factor off", async () => {
|
|
694
|
+
const client = fakeClient({
|
|
695
|
+
user: { email: "jane@example.com", id: "u1", twoFactorEnabled: true },
|
|
696
|
+
});
|
|
697
|
+
const { result } = renderSecurity(client);
|
|
698
|
+
await waitForLoaded(result);
|
|
699
|
+
expect(result.current.screenProps.twoFactor?.enabled).toBe(true);
|
|
700
|
+
let codes;
|
|
701
|
+
await act(async () => {
|
|
702
|
+
codes = await result.current.screenProps.twoFactor?.onRegenerateBackupCodes?.("pw");
|
|
703
|
+
});
|
|
704
|
+
expect(codes).toEqual(["new-1", "new-2"]);
|
|
705
|
+
expect(client.calls.generateBackupCodes).toEqual([{ password: "pw" }]);
|
|
706
|
+
await act(async () => {
|
|
707
|
+
await result.current.screenProps.twoFactor?.onDisable?.("pw");
|
|
708
|
+
});
|
|
709
|
+
expect(client.calls.disable).toEqual([{ password: "pw" }]);
|
|
710
|
+
expect(result.current.screenProps.twoFactor?.enabled).toBe(false);
|
|
711
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 2, sessions: 2 });
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
describe("sessions", () => {
|
|
715
|
+
it("signs out everywhere else with revokeOtherSessions and reloads only the sessions", async () => {
|
|
716
|
+
const client = fakeClient();
|
|
717
|
+
const { result } = renderSecurity(client);
|
|
718
|
+
await waitForLoaded(result);
|
|
719
|
+
await act(async () => {
|
|
720
|
+
await result.current.screenProps.sessions?.onRevokeOthers?.();
|
|
721
|
+
});
|
|
722
|
+
expect(countOf(client, "revokeOtherSessions")).toBe(1);
|
|
723
|
+
expect(countOf(client, "revokeSession")).toBe(0);
|
|
724
|
+
expect(loadCounts(client)).toEqual({ accounts: 1, passkeys: 1, session: 1, sessions: 2 });
|
|
725
|
+
expect(result.current.screenProps.sessions?.sessions).toEqual([CURRENT]);
|
|
726
|
+
});
|
|
727
|
+
it("signs out one session by its token", async () => {
|
|
728
|
+
const client = fakeClient();
|
|
729
|
+
const { result } = renderSecurity(client);
|
|
730
|
+
await waitForLoaded(result);
|
|
731
|
+
await act(async () => {
|
|
732
|
+
await result.current.screenProps.sessions?.onRevoke?.(OTHER);
|
|
733
|
+
});
|
|
734
|
+
expect(client.calls.revokeSession).toEqual([{ token: "tok-other" }]);
|
|
735
|
+
expect(result.current.screenProps.sessions?.sessions).toEqual([CURRENT]);
|
|
736
|
+
await expect(result.current.screenProps.sessions?.onRevoke?.({ id: "no-token" })).rejects.toThrow("Couldn't sign out that session.");
|
|
737
|
+
});
|
|
738
|
+
it("throws when signing out other sessions fails", async () => {
|
|
739
|
+
const client = fakeClient({}, { fail: { revokeOtherSessions: { error: { message: "Session expired", status: 401 } } } });
|
|
740
|
+
const { result } = renderSecurity(client);
|
|
741
|
+
await waitForLoaded(result);
|
|
742
|
+
await expect(result.current.screenProps.sessions?.onRevokeOthers?.()).rejects.toThrow("Session expired");
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
describe("loading and errors", () => {
|
|
746
|
+
it("shows a failed section's error on its card and keeps the other cards", async () => {
|
|
747
|
+
const client = fakeClient({}, {
|
|
748
|
+
fail: {
|
|
749
|
+
listAccounts: { error: { message: "Accounts down" } },
|
|
750
|
+
listSessions: { error: { code: "UNAUTHORIZED", message: "Sessions down" } },
|
|
751
|
+
listUserPasskeys: { error: { status: 500 } },
|
|
752
|
+
},
|
|
753
|
+
});
|
|
754
|
+
const { result } = renderSecurity(client);
|
|
755
|
+
await waitForLoaded(result);
|
|
756
|
+
expect(result.current.screenProps.error).toBeUndefined();
|
|
757
|
+
expect(result.current.screenProps.linkedAccounts?.error).toBe("Accounts down");
|
|
758
|
+
expect(result.current.screenProps.sessions?.error).toBe("Sessions down");
|
|
759
|
+
expect(result.current.screenProps.passkeys?.error).toBe("Couldn't load your passkeys.");
|
|
760
|
+
expect(result.current.screenProps.twoFactor).toBeDefined();
|
|
761
|
+
});
|
|
762
|
+
it("asks the user to sign in again when Better Auth needs a fresh session", async () => {
|
|
763
|
+
const stale = {
|
|
764
|
+
error: { code: "SESSION_NOT_FRESH", message: "Session is not fresh", status: 403 },
|
|
765
|
+
};
|
|
766
|
+
const client = fakeClient({ accounts: [GOOGLE] }, { fail: { "$fetch /terreno/set-password": stale, listSessions: stale, unlinkAccount: stale } });
|
|
767
|
+
client.state.accounts = [GOOGLE, { id: "acc-github", providerId: "github" }];
|
|
768
|
+
const { result } = renderSecurity(client);
|
|
769
|
+
await waitForLoaded(result);
|
|
770
|
+
expect(result.current.screenProps.sessions?.error).toBe(SIGN_IN_AGAIN_MESSAGE);
|
|
771
|
+
const google = linkedAccountsOf(result).accounts[0];
|
|
772
|
+
await expect(linkedAccountsOf(result).onUnlink?.("google", google)).rejects.toThrow(SIGN_IN_AGAIN_MESSAGE);
|
|
773
|
+
await expect(result.current.screenProps.password?.onSubmit({
|
|
774
|
+
mode: "set",
|
|
775
|
+
newPassword: "first-password-1",
|
|
776
|
+
revokeOtherSessions: false,
|
|
777
|
+
})).rejects.toThrow(SIGN_IN_AGAIN_MESSAGE);
|
|
778
|
+
});
|
|
779
|
+
it("keeps loaded rows when a refetch after a change fails", async () => {
|
|
780
|
+
const client = fakeClient();
|
|
781
|
+
const { result } = renderSecurity(client);
|
|
782
|
+
await waitForLoaded(result);
|
|
783
|
+
client.listSessions = async () => {
|
|
784
|
+
throw new Error("Network request failed");
|
|
785
|
+
};
|
|
786
|
+
await act(async () => {
|
|
787
|
+
await result.current.screenProps.sessions?.onRevokeOthers?.();
|
|
788
|
+
});
|
|
789
|
+
expect(result.current.screenProps.sessions?.error).toBe("Network request failed");
|
|
790
|
+
expect(result.current.screenProps.sessions?.sessions).toEqual([CURRENT, OTHER]);
|
|
791
|
+
});
|
|
792
|
+
it("shows a page error when no one is signed in", async () => {
|
|
793
|
+
const client = fakeClient({ user: null });
|
|
794
|
+
const { result } = renderSecurity(client);
|
|
795
|
+
await waitForLoaded(result);
|
|
796
|
+
expect(result.current.screenProps.error).toBe("Sign in to manage your security settings.");
|
|
797
|
+
});
|
|
798
|
+
it("shows a page error when the session fails to load, and retries every section", async () => {
|
|
799
|
+
const client = fakeClient();
|
|
800
|
+
const original = client.getSession;
|
|
801
|
+
client.getSession = async () => {
|
|
802
|
+
throw new Error("Offline");
|
|
803
|
+
};
|
|
804
|
+
const { result } = renderSecurity(client);
|
|
805
|
+
await waitForLoaded(result);
|
|
806
|
+
expect(result.current.screenProps.error).toBe("Offline");
|
|
807
|
+
client.getSession = original;
|
|
808
|
+
act(() => {
|
|
809
|
+
result.current.screenProps.onRetry();
|
|
810
|
+
});
|
|
811
|
+
await waitFor(() => expect(result.current.screenProps.error).toBeUndefined());
|
|
812
|
+
await waitForLoaded(result);
|
|
813
|
+
expect(loadCounts(client)).toEqual({ accounts: 2, passkeys: 2, session: 1, sessions: 2 });
|
|
814
|
+
});
|
|
815
|
+
it("shows the methods error and requests the methods again on retry", async () => {
|
|
816
|
+
const client = fakeClient();
|
|
817
|
+
const original = client.$fetch;
|
|
818
|
+
client.$fetch = async () => ({ data: null, error: { message: "Methods unavailable" } });
|
|
819
|
+
const warn = console.warn;
|
|
820
|
+
console.warn = () => { };
|
|
821
|
+
try {
|
|
822
|
+
const { result } = renderSecurity(client);
|
|
823
|
+
await waitForLoaded(result);
|
|
824
|
+
expect(result.current.screenProps.error).toBe("Methods unavailable");
|
|
825
|
+
expect(result.current.screenProps.sessions).toBeUndefined();
|
|
826
|
+
expect(countOf(client, "listAccounts")).toBe(0);
|
|
827
|
+
client.$fetch = original;
|
|
828
|
+
act(() => {
|
|
829
|
+
result.current.screenProps.onRetry();
|
|
830
|
+
});
|
|
831
|
+
await waitFor(() => expect(result.current.methods).toEqual(METHODS));
|
|
832
|
+
await waitForLoaded(result);
|
|
833
|
+
expect(result.current.screenProps.error).toBeUndefined();
|
|
834
|
+
expect(countOf(client, "listAccounts")).toBe(1);
|
|
835
|
+
}
|
|
836
|
+
finally {
|
|
837
|
+
console.warn = warn;
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
it("reloads every section through refetch", async () => {
|
|
841
|
+
const client = fakeClient();
|
|
842
|
+
const { result } = renderSecurity(client);
|
|
843
|
+
await waitForLoaded(result);
|
|
844
|
+
await act(async () => {
|
|
845
|
+
await result.current.refetch();
|
|
846
|
+
});
|
|
847
|
+
expect(loadCounts(client)).toEqual({ accounts: 2, passkeys: 2, session: 2, sessions: 2 });
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
//# sourceMappingURL=useAccountSecurity.isolated.js.map
|