@terreno/syncdb 57.21.0 → 58.0.0-beta.1
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 +43 -0
- package/README.md +7 -7
- 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 +10 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +237 -184
- 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 +60 -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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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/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.js +1 -1
- 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/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 +73 -1
- package/src/client.ts +87 -18
- 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 +2 -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/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 +1 -1
- 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
|
@@ -0,0 +1,1116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolated tests for useLoginController, with a fake Better Auth client at the network boundary
|
|
3
|
+
* and a real remembered-accounts store on memory storage. The controller imports
|
|
4
|
+
* betterAuthClient.ts (for bearer mode and the OAuth handoff), whose Expo plugin loads native
|
|
5
|
+
* modules, so the Expo plugin is replaced here, where the mock cannot leak into other suites.
|
|
6
|
+
*/
|
|
7
|
+
import { afterEach, describe, expect, it, mock, spyOn } 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 { SIGN_UP_CLOSED_NOTICE_TEXT, VERIFY_EMAIL_NOTICE_TEXT } = await import("../auth/loginErrors");
|
|
14
|
+
const { createRememberedAccountsStore } = await import("../auth/rememberedAccounts");
|
|
15
|
+
const { recordRememberedSignIn, useLoginController } = await import("../auth/useLoginController");
|
|
16
|
+
const { createBetterAuthClient } = await import("../auth/betterAuthClient");
|
|
17
|
+
const METHODS = {
|
|
18
|
+
accountLinking: { mode: "verified-email" },
|
|
19
|
+
emailPassword: true,
|
|
20
|
+
multiSession: true,
|
|
21
|
+
passkey: true,
|
|
22
|
+
providers: ["github", "google", "mock-oidc"],
|
|
23
|
+
signUp: true,
|
|
24
|
+
twoFactor: true,
|
|
25
|
+
};
|
|
26
|
+
const JANE = { email: "jane@example.com", id: "u1", image: null, name: "Jane" };
|
|
27
|
+
const BOB = { email: "bob@example.com", id: "u2", name: "Bob" };
|
|
28
|
+
const memoryStorage = () => {
|
|
29
|
+
const values = new Map();
|
|
30
|
+
return {
|
|
31
|
+
getItem: (key) => values.get(key) ?? null,
|
|
32
|
+
removeItem: (key) => {
|
|
33
|
+
values.delete(key);
|
|
34
|
+
},
|
|
35
|
+
setItem: (key, value) => {
|
|
36
|
+
values.set(key, value);
|
|
37
|
+
},
|
|
38
|
+
values,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const createStore = (rememberIdentity = true) => {
|
|
42
|
+
return createRememberedAccountsStore({ rememberIdentity, storage: memoryStorage() });
|
|
43
|
+
};
|
|
44
|
+
// A fake Better Auth client at the network boundary: each call records its arguments and answers
|
|
45
|
+
// from `state` the way the real client resolves `{data, error}`.
|
|
46
|
+
const fakeClient = (initial = {}, overrides = {}) => {
|
|
47
|
+
const state = {
|
|
48
|
+
deviceSessions: [],
|
|
49
|
+
methods: METHODS,
|
|
50
|
+
sessionUser: null,
|
|
51
|
+
...initial,
|
|
52
|
+
};
|
|
53
|
+
const calls = {
|
|
54
|
+
email: [],
|
|
55
|
+
getSession: 0,
|
|
56
|
+
listDeviceSessions: 0,
|
|
57
|
+
passkey: [],
|
|
58
|
+
setActive: [],
|
|
59
|
+
social: [],
|
|
60
|
+
verifyBackupCode: [],
|
|
61
|
+
verifyTotp: [],
|
|
62
|
+
};
|
|
63
|
+
const signedIn = (user) => {
|
|
64
|
+
state.sessionUser = user;
|
|
65
|
+
return { user };
|
|
66
|
+
};
|
|
67
|
+
const client = {
|
|
68
|
+
$fetch: async () => ({ data: state.methods, error: null }),
|
|
69
|
+
calls,
|
|
70
|
+
getSession: async () => {
|
|
71
|
+
calls.getSession += 1;
|
|
72
|
+
return {
|
|
73
|
+
data: state.sessionUser ? { session: { id: "s" }, user: state.sessionUser } : null,
|
|
74
|
+
error: null,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
signIn: {
|
|
78
|
+
email: async (body) => {
|
|
79
|
+
calls.email.push(body);
|
|
80
|
+
if (overrides.email) {
|
|
81
|
+
return overrides.email();
|
|
82
|
+
}
|
|
83
|
+
return { data: signedIn(JANE), error: null };
|
|
84
|
+
},
|
|
85
|
+
social: async (body) => {
|
|
86
|
+
calls.social.push(body);
|
|
87
|
+
if (overrides.social) {
|
|
88
|
+
return overrides.social();
|
|
89
|
+
}
|
|
90
|
+
// Native: the provider's browser flow finishes in-process and leaves a session.
|
|
91
|
+
state.sessionUser = JANE;
|
|
92
|
+
return { data: { redirect: false }, error: null };
|
|
93
|
+
},
|
|
94
|
+
...(overrides.withoutPasskey
|
|
95
|
+
? {}
|
|
96
|
+
: {
|
|
97
|
+
passkey: async (options) => {
|
|
98
|
+
calls.passkey.push(options);
|
|
99
|
+
if (overrides.passkey) {
|
|
100
|
+
return overrides.passkey();
|
|
101
|
+
}
|
|
102
|
+
return { data: signedIn(BOB), error: null };
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
state,
|
|
107
|
+
...(overrides.withoutMultiSession
|
|
108
|
+
? {}
|
|
109
|
+
: {
|
|
110
|
+
multiSession: {
|
|
111
|
+
listDeviceSessions: async () => {
|
|
112
|
+
calls.listDeviceSessions += 1;
|
|
113
|
+
return { data: state.deviceSessions, error: null };
|
|
114
|
+
},
|
|
115
|
+
setActive: async (body) => {
|
|
116
|
+
calls.setActive.push(body);
|
|
117
|
+
if (overrides.setActive) {
|
|
118
|
+
return overrides.setActive();
|
|
119
|
+
}
|
|
120
|
+
const match = state.deviceSessions.find((device) => device.session.token === body.sessionToken);
|
|
121
|
+
state.sessionUser = match?.user ?? null;
|
|
122
|
+
return { data: {}, error: null };
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
...(overrides.withoutTwoFactor
|
|
127
|
+
? {}
|
|
128
|
+
: {
|
|
129
|
+
twoFactor: {
|
|
130
|
+
verifyBackupCode: async (body) => {
|
|
131
|
+
calls.verifyBackupCode.push(body);
|
|
132
|
+
return overrides.verify ? overrides.verify() : { data: signedIn(JANE), error: null };
|
|
133
|
+
},
|
|
134
|
+
verifyTotp: async (body) => {
|
|
135
|
+
calls.verifyTotp.push(body);
|
|
136
|
+
return overrides.verify ? overrides.verify() : { data: signedIn(JANE), error: null };
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
141
|
+
return client;
|
|
142
|
+
};
|
|
143
|
+
const renderController = (options) => {
|
|
144
|
+
const onSignedIn = mock((_event) => { });
|
|
145
|
+
const store = options.rememberedAccounts ?? createStore();
|
|
146
|
+
const rendered = renderHook(() => useLoginController({ onSignedIn, rememberedAccounts: store, webAuth: "cookie", ...options }));
|
|
147
|
+
return { ...rendered, onSignedIn, store };
|
|
148
|
+
};
|
|
149
|
+
// Waits until the live-session check and the methods request have both settled.
|
|
150
|
+
const waitForLoginScreen = async (result, methods = true) => {
|
|
151
|
+
await waitFor(() => expect(result.current.step).toBe("login"));
|
|
152
|
+
if (methods) {
|
|
153
|
+
await waitFor(() => expect(result.current.methods).toBeDefined());
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const globalWithWindow = globalThis;
|
|
157
|
+
describe("useLoginController", () => {
|
|
158
|
+
afterEach(() => {
|
|
159
|
+
delete globalWithWindow.window;
|
|
160
|
+
// Restores console methods a test spied on.
|
|
161
|
+
for (const method of [console.warn, console.error, console.info]) {
|
|
162
|
+
method.mockRestore?.();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
it("lets a device session take precedence over a remembered account for the same user", async () => {
|
|
166
|
+
const store = createStore();
|
|
167
|
+
await store.record({ method: "google", userId: JANE.id });
|
|
168
|
+
await store.record({ method: "email", userId: BOB.id });
|
|
169
|
+
const client = fakeClient({ deviceSessions: [{ session: { token: "tok-jane" }, user: JANE }] });
|
|
170
|
+
const { result } = renderController({ client, rememberedAccounts: store });
|
|
171
|
+
await waitForLoginScreen(result);
|
|
172
|
+
await waitFor(() => expect(result.current.screenProps.currentSessions).toHaveLength(1));
|
|
173
|
+
expect(result.current.screenProps.currentSessions).toEqual([
|
|
174
|
+
{ email: "jane@example.com", id: "tok-jane", method: "google", name: "Jane" },
|
|
175
|
+
]);
|
|
176
|
+
expect(result.current.screenProps.rememberedAccounts).toEqual([{ id: "u2", method: "email" }]);
|
|
177
|
+
expect(result.current.screenProps.lastUsedMethod).toBe("email");
|
|
178
|
+
});
|
|
179
|
+
it("skips multiSession in bearer mode and offers remembered accounts instead", async () => {
|
|
180
|
+
const store = createStore();
|
|
181
|
+
await store.record({ method: "google", userId: JANE.id });
|
|
182
|
+
const client = fakeClient({ deviceSessions: [{ session: { token: "tok-jane" }, user: JANE }] });
|
|
183
|
+
const { result } = renderController({
|
|
184
|
+
client,
|
|
185
|
+
getBearerToken: () => null,
|
|
186
|
+
rememberedAccounts: store,
|
|
187
|
+
webAuth: "bearer",
|
|
188
|
+
});
|
|
189
|
+
await waitForLoginScreen(result);
|
|
190
|
+
// No token means signed out without asking the server.
|
|
191
|
+
expect(client.calls.getSession).toBe(0);
|
|
192
|
+
expect(client.calls.listDeviceSessions).toBe(0);
|
|
193
|
+
expect(result.current.screenProps.currentSessions).toEqual([]);
|
|
194
|
+
expect(result.current.screenProps.rememberedAccounts).toEqual([{ id: "u1", method: "google" }]);
|
|
195
|
+
});
|
|
196
|
+
it("skips the screen when a live bearer session exists", async () => {
|
|
197
|
+
const client = fakeClient({ sessionUser: JANE });
|
|
198
|
+
const { result, onSignedIn } = renderController({
|
|
199
|
+
client,
|
|
200
|
+
getBearerToken: () => "bearer-token",
|
|
201
|
+
webAuth: "bearer",
|
|
202
|
+
});
|
|
203
|
+
await waitFor(() => expect(onSignedIn).toHaveBeenCalledTimes(1));
|
|
204
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: undefined, user: JANE }]);
|
|
205
|
+
expect(result.current.step).toBe("signedIn");
|
|
206
|
+
});
|
|
207
|
+
it("records the method of a live cookie session the server reports, and shows the screen on an 'add account' route", async () => {
|
|
208
|
+
const user = { ...JANE, lastLoginMethod: "github" };
|
|
209
|
+
const store = createStore();
|
|
210
|
+
const live = renderController({
|
|
211
|
+
client: fakeClient({ sessionUser: user }),
|
|
212
|
+
rememberedAccounts: store,
|
|
213
|
+
});
|
|
214
|
+
await waitFor(() => expect(live.onSignedIn).toHaveBeenCalledTimes(1));
|
|
215
|
+
expect(live.onSignedIn.mock.calls[0]).toEqual([{ method: "github", user }]);
|
|
216
|
+
expect(store.list().map(({ method, userId }) => ({ method, userId }))).toEqual([
|
|
217
|
+
{ method: "github", userId: "u1" },
|
|
218
|
+
]);
|
|
219
|
+
const addAccount = renderController({
|
|
220
|
+
client: fakeClient({ sessionUser: user }),
|
|
221
|
+
skipWhenSignedIn: false,
|
|
222
|
+
});
|
|
223
|
+
await waitForLoginScreen(addAccount.result);
|
|
224
|
+
expect(addAccount.onSignedIn).not.toHaveBeenCalled();
|
|
225
|
+
});
|
|
226
|
+
it("shows the screen when the session check throws", async () => {
|
|
227
|
+
spyOn(console, "warn").mockImplementation(() => { });
|
|
228
|
+
const client = fakeClient();
|
|
229
|
+
client.getSession = async () => {
|
|
230
|
+
throw new Error("offline");
|
|
231
|
+
};
|
|
232
|
+
const { result } = renderController({ client });
|
|
233
|
+
await waitForLoginScreen(result);
|
|
234
|
+
});
|
|
235
|
+
it("records a remembered account after a successful email sign-in", async () => {
|
|
236
|
+
const store = createStore(true);
|
|
237
|
+
const client = fakeClient();
|
|
238
|
+
const { result, onSignedIn } = renderController({ client, rememberedAccounts: store });
|
|
239
|
+
await waitForLoginScreen(result);
|
|
240
|
+
await act(async () => {
|
|
241
|
+
await result.current.screenProps.onSubmit({ email: " jane@example.com ", password: "pw" });
|
|
242
|
+
});
|
|
243
|
+
expect(client.calls.email).toEqual([{ email: "jane@example.com", password: "pw" }]);
|
|
244
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "email", user: JANE }]);
|
|
245
|
+
expect(store.list()).toEqual([
|
|
246
|
+
expect.objectContaining({
|
|
247
|
+
email: "j***@e***.com",
|
|
248
|
+
method: "email",
|
|
249
|
+
name: "Jane",
|
|
250
|
+
userId: "u1",
|
|
251
|
+
}),
|
|
252
|
+
]);
|
|
253
|
+
expect(result.current.step).toBe("signedIn");
|
|
254
|
+
});
|
|
255
|
+
it("records only the method when rememberIdentity is false", async () => {
|
|
256
|
+
const store = createStore(true);
|
|
257
|
+
const { result } = renderController({
|
|
258
|
+
client: fakeClient(),
|
|
259
|
+
rememberedAccounts: store,
|
|
260
|
+
rememberIdentity: false,
|
|
261
|
+
});
|
|
262
|
+
await waitForLoginScreen(result);
|
|
263
|
+
await act(async () => {
|
|
264
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
265
|
+
});
|
|
266
|
+
expect(store.list()).toEqual([{ lastUsedAt: expect.any(String), method: "email", userId: "u1" }]);
|
|
267
|
+
});
|
|
268
|
+
it("fires onTwoFactorRequired on a two-factor redirect instead of signing in", async () => {
|
|
269
|
+
const onTwoFactorRequired = mock(() => { });
|
|
270
|
+
const client = fakeClient({}, {
|
|
271
|
+
email: async () => ({
|
|
272
|
+
data: { twoFactorMethods: ["totp"], twoFactorRedirect: true },
|
|
273
|
+
error: null,
|
|
274
|
+
}),
|
|
275
|
+
});
|
|
276
|
+
const { result, onSignedIn, store } = renderController({ client, onTwoFactorRequired });
|
|
277
|
+
await waitForLoginScreen(result);
|
|
278
|
+
await act(async () => {
|
|
279
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
280
|
+
});
|
|
281
|
+
expect(result.current.twoFactor.initialTrustDevice).toBeUndefined();
|
|
282
|
+
expect(onTwoFactorRequired).toHaveBeenCalledWith({ method: "email", twoFactorMethods: ["totp"] });
|
|
283
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
284
|
+
expect(result.current.step).toBe("login");
|
|
285
|
+
expect(store.list()).toEqual([]);
|
|
286
|
+
});
|
|
287
|
+
it("forwards initialTrustDevice false onto the inline challenge", async () => {
|
|
288
|
+
const client = fakeClient({}, {
|
|
289
|
+
email: async () => ({
|
|
290
|
+
data: { twoFactorMethods: ["totp"], twoFactorRedirect: true },
|
|
291
|
+
error: null,
|
|
292
|
+
}),
|
|
293
|
+
});
|
|
294
|
+
const { result } = renderController({ client, initialTrustDevice: false });
|
|
295
|
+
await waitForLoginScreen(result);
|
|
296
|
+
await act(async () => {
|
|
297
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
298
|
+
});
|
|
299
|
+
expect(result.current.step).toBe("twoFactor");
|
|
300
|
+
expect(result.current.twoFactor.initialTrustDevice).toBe(false);
|
|
301
|
+
});
|
|
302
|
+
it("runs the inline two-factor challenge when no onTwoFactorRequired is given", async () => {
|
|
303
|
+
let verifyResult = {
|
|
304
|
+
data: null,
|
|
305
|
+
error: { code: "INVALID_CODE", message: "Invalid code", status: 401 },
|
|
306
|
+
};
|
|
307
|
+
const client = fakeClient({}, {
|
|
308
|
+
email: async () => ({
|
|
309
|
+
data: { twoFactorMethods: ["totp"], twoFactorRedirect: true },
|
|
310
|
+
error: null,
|
|
311
|
+
}),
|
|
312
|
+
verify: async () => verifyResult,
|
|
313
|
+
});
|
|
314
|
+
const { result, onSignedIn, store } = renderController({ client });
|
|
315
|
+
await waitForLoginScreen(result);
|
|
316
|
+
await act(async () => {
|
|
317
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
318
|
+
});
|
|
319
|
+
expect(result.current.step).toBe("twoFactor");
|
|
320
|
+
expect(result.current.twoFactor.twoFactorMethods).toEqual(["totp"]);
|
|
321
|
+
await act(async () => {
|
|
322
|
+
await result.current.twoFactor.onSubmit({ code: "000000", kind: "totp", trustDevice: false });
|
|
323
|
+
});
|
|
324
|
+
expect(result.current.twoFactor.error).toBe("Invalid code");
|
|
325
|
+
act(() => result.current.twoFactor.onCancel());
|
|
326
|
+
expect(result.current.step).toBe("login");
|
|
327
|
+
await act(async () => {
|
|
328
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
329
|
+
});
|
|
330
|
+
verifyResult = { data: { user: JANE }, error: null };
|
|
331
|
+
await act(async () => {
|
|
332
|
+
await result.current.twoFactor.onSubmit({
|
|
333
|
+
code: "abcde-12345",
|
|
334
|
+
kind: "backup",
|
|
335
|
+
trustDevice: true,
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
expect(client.calls.verifyTotp).toEqual([{ code: "000000", trustDevice: false }]);
|
|
339
|
+
expect(client.calls.verifyBackupCode).toEqual([{ code: "abcde-12345", trustDevice: true }]);
|
|
340
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "email", user: JANE }]);
|
|
341
|
+
expect(store.list()[0]).toEqual(expect.objectContaining({ method: "email", userId: "u1" }));
|
|
342
|
+
});
|
|
343
|
+
it("reports a two-factor failure when the client has no twoFactor, throws, or returns no user", async () => {
|
|
344
|
+
spyOn(console, "error").mockImplementation(() => { });
|
|
345
|
+
const bare = renderController({ client: fakeClient({}, { withoutTwoFactor: true }) });
|
|
346
|
+
await waitForLoginScreen(bare.result);
|
|
347
|
+
await act(async () => {
|
|
348
|
+
await bare.result.current.twoFactor.onSubmit({ code: "1", kind: "totp", trustDevice: false });
|
|
349
|
+
});
|
|
350
|
+
expect(bare.result.current.twoFactor.error).toBe("That code didn't work. Codes change every 30 seconds, so enter the one your app shows now.");
|
|
351
|
+
const throwing = renderController({
|
|
352
|
+
client: fakeClient({}, {
|
|
353
|
+
verify: async () => {
|
|
354
|
+
throw new Error("network");
|
|
355
|
+
},
|
|
356
|
+
}),
|
|
357
|
+
});
|
|
358
|
+
await waitForLoginScreen(throwing.result);
|
|
359
|
+
await act(async () => {
|
|
360
|
+
await throwing.result.current.twoFactor.onSubmit({
|
|
361
|
+
code: "1",
|
|
362
|
+
kind: "totp",
|
|
363
|
+
trustDevice: false,
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
expect(throwing.result.current.twoFactor.error).toBe("That code didn't work. Codes change every 30 seconds, so enter the one your app shows now.");
|
|
367
|
+
const noUser = renderController({
|
|
368
|
+
client: fakeClient({}, { verify: async () => ({ data: {}, error: null }) }),
|
|
369
|
+
});
|
|
370
|
+
await waitForLoginScreen(noUser.result);
|
|
371
|
+
await act(async () => {
|
|
372
|
+
await noUser.result.current.twoFactor.onSubmit({ code: "1", kind: "totp", trustDevice: false });
|
|
373
|
+
});
|
|
374
|
+
expect(noUser.result.current.twoFactor.error).toBe("That code didn't work. Codes change every 30 seconds, so enter the one your app shows now.");
|
|
375
|
+
expect(noUser.onSignedIn).not.toHaveBeenCalled();
|
|
376
|
+
});
|
|
377
|
+
it("turns account_not_linked into guidance for each linking mode", async () => {
|
|
378
|
+
const texts = [];
|
|
379
|
+
for (const mode of ["verified-email", "explicit", "never"]) {
|
|
380
|
+
const store = createStore();
|
|
381
|
+
await store.record({ method: "google", userId: JANE.id });
|
|
382
|
+
const { result } = renderController({
|
|
383
|
+
client: fakeClient({ methods: { ...METHODS, accountLinking: { mode } } }),
|
|
384
|
+
error: "account_not_linked",
|
|
385
|
+
rememberedAccounts: store,
|
|
386
|
+
});
|
|
387
|
+
await waitForLoginScreen(result);
|
|
388
|
+
expect(result.current.screenProps.notice?.tone).toBe("warning");
|
|
389
|
+
expect(result.current.screenProps.error).toBeUndefined();
|
|
390
|
+
texts.push(result.current.screenProps.notice?.text ?? "");
|
|
391
|
+
}
|
|
392
|
+
expect(texts[0]).toContain("Verify your email address, then sign in again to link");
|
|
393
|
+
expect(texts[1]).toBe("That email is already used with Google. Sign in with Google, then link it from Security.");
|
|
394
|
+
expect(texts[2]).toBe("That email already has an account. Sign in with Google instead.");
|
|
395
|
+
});
|
|
396
|
+
it("names a remembered method or a provider id that matches an Object.prototype key as text", async () => {
|
|
397
|
+
const texts = [];
|
|
398
|
+
for (const method of ["__proto__", "constructor"]) {
|
|
399
|
+
const store = createStore();
|
|
400
|
+
await store.record({ method, userId: JANE.id });
|
|
401
|
+
const { result } = renderController({
|
|
402
|
+
client: fakeClient({
|
|
403
|
+
methods: { ...METHODS, accountLinking: { mode: "never" }, providers: [method] },
|
|
404
|
+
}),
|
|
405
|
+
error: "account_not_linked",
|
|
406
|
+
providerLabels: { "mock-oidc": "Mock OIDC" },
|
|
407
|
+
rememberedAccounts: store,
|
|
408
|
+
});
|
|
409
|
+
await waitForLoginScreen(result);
|
|
410
|
+
texts.push(result.current.screenProps.notice?.text ?? "");
|
|
411
|
+
const labels = result.current.screenProps.genericProviders?.map(({ label }) => label) ?? [];
|
|
412
|
+
expect(labels.every((label) => typeof label === "string")).toBe(true);
|
|
413
|
+
}
|
|
414
|
+
expect(texts).toEqual([
|
|
415
|
+
"That email already has an account. Sign in with Proto instead.",
|
|
416
|
+
"That email already has an account. Sign in with Constructor instead.",
|
|
417
|
+
]);
|
|
418
|
+
});
|
|
419
|
+
it("maps the ID-token refusal 'account not linked' from a sign-in response", async () => {
|
|
420
|
+
const client = fakeClient({ methods: { ...METHODS, accountLinking: { mode: "never" } } }, { social: async () => ({ data: null, error: { message: "account not linked", status: 401 } }) });
|
|
421
|
+
const { result } = renderController({ client });
|
|
422
|
+
await waitForLoginScreen(result);
|
|
423
|
+
await act(async () => {
|
|
424
|
+
await result.current.signInSocial("github");
|
|
425
|
+
});
|
|
426
|
+
expect(result.current.screenProps.notice?.text).toBe("That email already has an account. Sign in the way you did before instead.");
|
|
427
|
+
});
|
|
428
|
+
it("tells the user to verify their email on VERIFY_EMAIL_TO_USE_ACCOUNT", async () => {
|
|
429
|
+
const client = fakeClient({}, {
|
|
430
|
+
email: async () => ({
|
|
431
|
+
data: null,
|
|
432
|
+
error: {
|
|
433
|
+
code: "VERIFY_EMAIL_TO_USE_ACCOUNT",
|
|
434
|
+
message: "Verify your email to use this account",
|
|
435
|
+
status: 409,
|
|
436
|
+
},
|
|
437
|
+
}),
|
|
438
|
+
});
|
|
439
|
+
const { result, onSignedIn } = renderController({ client });
|
|
440
|
+
await waitForLoginScreen(result);
|
|
441
|
+
await act(async () => {
|
|
442
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
443
|
+
});
|
|
444
|
+
expect(result.current.screenProps.notice).toEqual({
|
|
445
|
+
text: VERIFY_EMAIL_NOTICE_TEXT,
|
|
446
|
+
title: "Verify your email",
|
|
447
|
+
tone: "warning",
|
|
448
|
+
});
|
|
449
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
450
|
+
const fromUrl = renderController({
|
|
451
|
+
client: fakeClient(),
|
|
452
|
+
error: ["VERIFY_EMAIL_TO_USE_ACCOUNT"],
|
|
453
|
+
});
|
|
454
|
+
await waitForLoginScreen(fromUrl.result);
|
|
455
|
+
expect(fromUrl.result.current.screenProps.notice?.text).toBe(VERIFY_EMAIL_NOTICE_TEXT);
|
|
456
|
+
});
|
|
457
|
+
it("shows the administrator notice and hides sign-up on signup_disabled", async () => {
|
|
458
|
+
const onSignUpPress = mock(() => { });
|
|
459
|
+
const { result } = renderController({
|
|
460
|
+
client: fakeClient(),
|
|
461
|
+
error: "signup_disabled",
|
|
462
|
+
onSignUpPress,
|
|
463
|
+
});
|
|
464
|
+
await waitForLoginScreen(result);
|
|
465
|
+
expect(result.current.screenProps.notice).toEqual({
|
|
466
|
+
text: SIGN_UP_CLOSED_NOTICE_TEXT,
|
|
467
|
+
title: "Sign-up is closed",
|
|
468
|
+
tone: "warning",
|
|
469
|
+
});
|
|
470
|
+
expect(result.current.screenProps.onSignUpPress).toBeUndefined();
|
|
471
|
+
});
|
|
472
|
+
it("offers sign-up only while the server's sign-up is open", async () => {
|
|
473
|
+
const onSignUpPress = mock(() => { });
|
|
474
|
+
const open = renderController({ client: fakeClient(), onSignUpPress });
|
|
475
|
+
await waitForLoginScreen(open.result);
|
|
476
|
+
expect(open.result.current.screenProps.onSignUpPress).toBe(onSignUpPress);
|
|
477
|
+
const closed = renderController({
|
|
478
|
+
client: fakeClient({ methods: { ...METHODS, signUp: false } }),
|
|
479
|
+
onSignUpPress,
|
|
480
|
+
});
|
|
481
|
+
await waitForLoginScreen(closed.result);
|
|
482
|
+
expect(closed.result.current.screenProps.onSignUpPress).toBeUndefined();
|
|
483
|
+
});
|
|
484
|
+
it("follows a new ?error= and never shows URL text for an unknown code", async () => {
|
|
485
|
+
let error = "provider_not_found";
|
|
486
|
+
const onSignedIn = mock((_event) => { });
|
|
487
|
+
const store = createStore();
|
|
488
|
+
const client = fakeClient();
|
|
489
|
+
const { result, rerender } = renderHook(() => useLoginController({ client, error, onSignedIn, rememberedAccounts: store, webAuth: "cookie" }));
|
|
490
|
+
await waitForLoginScreen(result);
|
|
491
|
+
expect(result.current.screenProps.error).toBe("That sign-in provider is not available.");
|
|
492
|
+
error = "<script>alert(1)</script>";
|
|
493
|
+
rerender({});
|
|
494
|
+
await waitFor(() => expect(result.current.screenProps.error).toBe("Sign in failed. Please try again."));
|
|
495
|
+
});
|
|
496
|
+
it("shows the server's message for other refused sign-ins, and a generic one when sign-in throws", async () => {
|
|
497
|
+
spyOn(console, "error").mockImplementation(() => { });
|
|
498
|
+
const refused = renderController({
|
|
499
|
+
client: fakeClient({}, {
|
|
500
|
+
email: async () => ({
|
|
501
|
+
data: null,
|
|
502
|
+
error: { message: "Invalid email or password", status: 401 },
|
|
503
|
+
}),
|
|
504
|
+
}),
|
|
505
|
+
});
|
|
506
|
+
await waitForLoginScreen(refused.result);
|
|
507
|
+
await act(async () => {
|
|
508
|
+
await refused.result.current.signInEmail({ email: "a@b.co", password: "x" });
|
|
509
|
+
});
|
|
510
|
+
expect(refused.result.current.screenProps.passwordError).toBe("That password doesn't match. Try again or reset it.");
|
|
511
|
+
expect(refused.result.current.screenProps.error).toBeUndefined();
|
|
512
|
+
expect(refused.result.current.screenProps.loading).toBe(false);
|
|
513
|
+
const throwing = renderController({
|
|
514
|
+
client: fakeClient({}, {
|
|
515
|
+
email: async () => {
|
|
516
|
+
throw new Error("network down");
|
|
517
|
+
},
|
|
518
|
+
}),
|
|
519
|
+
});
|
|
520
|
+
await waitForLoginScreen(throwing.result);
|
|
521
|
+
await act(async () => {
|
|
522
|
+
await throwing.result.current.signInEmail({});
|
|
523
|
+
});
|
|
524
|
+
expect(throwing.result.current.screenProps.error).toBe("Sign in failed. Please try again.");
|
|
525
|
+
const noSession = renderController({
|
|
526
|
+
client: fakeClient({}, { email: async () => ({ data: {}, error: null }) }),
|
|
527
|
+
});
|
|
528
|
+
await waitForLoginScreen(noSession.result);
|
|
529
|
+
await act(async () => {
|
|
530
|
+
await noSession.result.current.signInEmail({ email: "a@b.co", password: "x" });
|
|
531
|
+
});
|
|
532
|
+
expect(noSession.result.current.screenProps.error).toBe("Sign in failed. Please try again.");
|
|
533
|
+
expect(noSession.onSignedIn).not.toHaveBeenCalled();
|
|
534
|
+
});
|
|
535
|
+
it("splits branded and generic providers and signs in with signIn.social outside bearer mode", async () => {
|
|
536
|
+
const store = createStore();
|
|
537
|
+
const client = fakeClient();
|
|
538
|
+
const { result, onSignedIn } = renderController({
|
|
539
|
+
callbackURL: "/login",
|
|
540
|
+
client,
|
|
541
|
+
errorCallbackURL: "/login",
|
|
542
|
+
providerLabels: { "mock-oidc": "Mock OIDC" },
|
|
543
|
+
rememberedAccounts: store,
|
|
544
|
+
});
|
|
545
|
+
await waitForLoginScreen(result);
|
|
546
|
+
expect(result.current.screenProps.oauthProviders?.map(({ provider }) => provider)).toEqual([
|
|
547
|
+
"google",
|
|
548
|
+
"github",
|
|
549
|
+
]);
|
|
550
|
+
expect(result.current.screenProps.genericProviders?.map(({ id, label }) => ({ id, label }))).toEqual([{ id: "mock-oidc", label: "Mock OIDC" }]);
|
|
551
|
+
await act(async () => {
|
|
552
|
+
await result.current.screenProps.genericProviders?.[0].onPress();
|
|
553
|
+
});
|
|
554
|
+
expect(client.calls.social).toEqual([
|
|
555
|
+
{ callbackURL: "/login", errorCallbackURL: "/login", provider: "mock-oidc" },
|
|
556
|
+
]);
|
|
557
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "mock-oidc", user: JANE }]);
|
|
558
|
+
expect(store.list()[0]).toEqual(expect.objectContaining({ method: "mock-oidc" }));
|
|
559
|
+
});
|
|
560
|
+
it("labels an unlabelled generic provider from its id and presses branded buttons", async () => {
|
|
561
|
+
const client = fakeClient();
|
|
562
|
+
const { result } = renderController({ client });
|
|
563
|
+
await waitForLoginScreen(result);
|
|
564
|
+
expect(result.current.screenProps.genericProviders?.[0].label).toBe("Mock Oidc");
|
|
565
|
+
await act(async () => {
|
|
566
|
+
await result.current.screenProps.oauthProviders?.[0].onPress();
|
|
567
|
+
});
|
|
568
|
+
expect(client.calls.social).toEqual([{ provider: "google" }]);
|
|
569
|
+
});
|
|
570
|
+
it("waits for a browser redirect instead of reading the session", async () => {
|
|
571
|
+
globalWithWindow.window = {};
|
|
572
|
+
const client = fakeClient({}, { social: async () => ({ data: { redirect: true, url: "https://github.com/login" }, error: null }) });
|
|
573
|
+
const { result, onSignedIn } = renderController({ client });
|
|
574
|
+
await waitForLoginScreen(result);
|
|
575
|
+
const sessionChecks = client.calls.getSession;
|
|
576
|
+
await act(async () => {
|
|
577
|
+
await result.current.signInSocial("github");
|
|
578
|
+
});
|
|
579
|
+
expect(client.calls.getSession).toBe(sessionChecks);
|
|
580
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
581
|
+
expect(result.current.screenProps.loading).toBe(false);
|
|
582
|
+
});
|
|
583
|
+
it("records the provider a redirecting sign-in started with when the page returns signed in", async () => {
|
|
584
|
+
const values = new Map();
|
|
585
|
+
globalWithWindow.window = {
|
|
586
|
+
sessionStorage: {
|
|
587
|
+
getItem: (key) => values.get(key) ?? null,
|
|
588
|
+
removeItem: (key) => {
|
|
589
|
+
values.delete(key);
|
|
590
|
+
},
|
|
591
|
+
setItem: (key, value) => {
|
|
592
|
+
values.set(key, value);
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
};
|
|
596
|
+
const leaving = renderController({
|
|
597
|
+
client: fakeClient({}, { social: async () => ({ data: { url: "https://x" }, error: null }) }),
|
|
598
|
+
});
|
|
599
|
+
await waitForLoginScreen(leaving.result);
|
|
600
|
+
await act(async () => {
|
|
601
|
+
await leaving.result.current.signInSocial("github");
|
|
602
|
+
});
|
|
603
|
+
expect(values.get("terreno_login_pending_method")).toBe("github");
|
|
604
|
+
// The provider sends the page back with a session.
|
|
605
|
+
const store = createStore();
|
|
606
|
+
const returned = renderController({
|
|
607
|
+
client: fakeClient({ sessionUser: JANE }),
|
|
608
|
+
rememberedAccounts: store,
|
|
609
|
+
});
|
|
610
|
+
await waitFor(() => expect(returned.onSignedIn).toHaveBeenCalledTimes(1));
|
|
611
|
+
expect(returned.onSignedIn.mock.calls[0]).toEqual([{ method: "github", user: JANE }]);
|
|
612
|
+
expect(values.has("terreno_login_pending_method")).toBe(false);
|
|
613
|
+
});
|
|
614
|
+
it("routes social sign-in through the OAuth handoff in bearer mode", async () => {
|
|
615
|
+
const assign = mock((_url) => { });
|
|
616
|
+
const sessionStorage = memoryStorage();
|
|
617
|
+
globalWithWindow.window = {
|
|
618
|
+
localStorage: memoryStorage(),
|
|
619
|
+
location: { assign, href: "http://app.test/login" },
|
|
620
|
+
sessionStorage,
|
|
621
|
+
};
|
|
622
|
+
const originalFetch = globalThis.fetch;
|
|
623
|
+
// The real client's requests: only the methods endpoint answers; nothing is signed in.
|
|
624
|
+
globalThis.fetch = (async (input) => {
|
|
625
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
626
|
+
return url.includes("/terreno/methods") ? Response.json(METHODS) : Response.json(null);
|
|
627
|
+
});
|
|
628
|
+
try {
|
|
629
|
+
const client = createBetterAuthClient({
|
|
630
|
+
baseURL: "http://api.test",
|
|
631
|
+
features: { multiSession: true, passkey: true, twoFactor: true },
|
|
632
|
+
scheme: "terreno",
|
|
633
|
+
webAuth: "bearer",
|
|
634
|
+
});
|
|
635
|
+
const onSignedIn = mock((_event) => { });
|
|
636
|
+
const { result } = renderHook(() => useLoginController({
|
|
637
|
+
callbackURL: "/login",
|
|
638
|
+
client,
|
|
639
|
+
onSignedIn,
|
|
640
|
+
rememberedAccounts: createStore(),
|
|
641
|
+
}));
|
|
642
|
+
await waitForLoginScreen(result);
|
|
643
|
+
await act(async () => {
|
|
644
|
+
await result.current.signInSocial("github");
|
|
645
|
+
});
|
|
646
|
+
const started = new URL(assign.mock.calls[0][0]);
|
|
647
|
+
expect(started.origin).toBe("http://api.test");
|
|
648
|
+
expect(started.pathname).toBe("/api/auth/oauth-handoff/start");
|
|
649
|
+
expect(started.searchParams.get("provider")).toBe("github");
|
|
650
|
+
expect(new URL(started.searchParams.get("callbackURL") ?? "").pathname).toBe("/login");
|
|
651
|
+
expect(sessionStorage.values.get("terreno_login_pending_method")).toBe("github");
|
|
652
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
653
|
+
}
|
|
654
|
+
finally {
|
|
655
|
+
globalThis.fetch = originalFetch;
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
// signIn.social answered without a redirect URL, which happens on native once the provider's
|
|
659
|
+
// browser flow is over. On native a refused sign-in comes back the same way: Better Auth's Expo
|
|
660
|
+
// plugin consumes the `?error=` deep link, so there is nothing to show (see the how-to).
|
|
661
|
+
it("does nothing more when signIn.social returns no redirect URL and leaves no session", async () => {
|
|
662
|
+
const client = fakeClient({}, { social: async () => ({ data: { redirect: false }, error: null }) });
|
|
663
|
+
const { result, onSignedIn } = renderController({ client });
|
|
664
|
+
await waitForLoginScreen(result);
|
|
665
|
+
await act(async () => {
|
|
666
|
+
await result.current.signInSocial("github");
|
|
667
|
+
});
|
|
668
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
669
|
+
expect(result.current.screenProps.error).toBeUndefined();
|
|
670
|
+
});
|
|
671
|
+
it("signs in with a passkey from the button and reports failures", async () => {
|
|
672
|
+
let passkeyResult = {
|
|
673
|
+
data: null,
|
|
674
|
+
error: { code: "AUTH_CANCELLED", message: "Authentication cancelled", status: 400 },
|
|
675
|
+
};
|
|
676
|
+
const client = fakeClient({}, { passkey: async () => passkeyResult });
|
|
677
|
+
const { result, onSignedIn, store } = renderController({ client });
|
|
678
|
+
await waitForLoginScreen(result);
|
|
679
|
+
expect(result.current.screenProps.passkeyAutofill).toBe(true);
|
|
680
|
+
await act(async () => {
|
|
681
|
+
await result.current.screenProps.onPasskeyPress?.();
|
|
682
|
+
});
|
|
683
|
+
expect(result.current.screenProps.error).toBeUndefined();
|
|
684
|
+
expect(result.current.screenProps.notice).toEqual({
|
|
685
|
+
text: "Passkey sign-in was cancelled. Try again or choose another way.",
|
|
686
|
+
tone: "info",
|
|
687
|
+
});
|
|
688
|
+
passkeyResult = { data: null, error: { status: 400 } };
|
|
689
|
+
await act(async () => {
|
|
690
|
+
await result.current.signInPasskey();
|
|
691
|
+
});
|
|
692
|
+
expect(result.current.screenProps.error).toBe("Passkey sign-in failed. Please try again.");
|
|
693
|
+
passkeyResult = { data: { user: BOB }, error: null };
|
|
694
|
+
await act(async () => {
|
|
695
|
+
await result.current.signInPasskey();
|
|
696
|
+
});
|
|
697
|
+
expect(client.calls.passkey).toEqual([undefined, undefined, undefined]);
|
|
698
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "passkey", user: BOB }]);
|
|
699
|
+
expect(store.list()[0]).toEqual(expect.objectContaining({ method: "passkey", userId: "u2" }));
|
|
700
|
+
});
|
|
701
|
+
it("reports a thrown passkey sign-in and hides passkeys the client or server lacks", async () => {
|
|
702
|
+
spyOn(console, "error").mockImplementation(() => { });
|
|
703
|
+
const throwing = renderController({
|
|
704
|
+
client: fakeClient({}, {
|
|
705
|
+
passkey: async () => {
|
|
706
|
+
throw new Error("webauthn");
|
|
707
|
+
},
|
|
708
|
+
}),
|
|
709
|
+
});
|
|
710
|
+
await waitForLoginScreen(throwing.result);
|
|
711
|
+
await act(async () => {
|
|
712
|
+
await throwing.result.current.signInPasskey();
|
|
713
|
+
});
|
|
714
|
+
expect(throwing.result.current.screenProps.error).toBe("Passkey sign-in failed. Please try again.");
|
|
715
|
+
const noPlugin = renderController({ client: fakeClient({}, { withoutPasskey: true }) });
|
|
716
|
+
await waitForLoginScreen(noPlugin.result);
|
|
717
|
+
expect(noPlugin.result.current.screenProps.onPasskeyPress).toBeUndefined();
|
|
718
|
+
await act(async () => {
|
|
719
|
+
await noPlugin.result.current.signInPasskey();
|
|
720
|
+
});
|
|
721
|
+
const serverOff = renderController({
|
|
722
|
+
client: fakeClient({ methods: { ...METHODS, passkey: false } }),
|
|
723
|
+
});
|
|
724
|
+
await waitForLoginScreen(serverOff.result);
|
|
725
|
+
expect(serverOff.result.current.screenProps.onPasskeyPress).toBeUndefined();
|
|
726
|
+
expect(serverOff.result.current.screenProps.passkeyAutofill).toBe(false);
|
|
727
|
+
});
|
|
728
|
+
it("starts passkey autofill on web when the browser supports conditional mediation", async () => {
|
|
729
|
+
globalWithWindow.window = {
|
|
730
|
+
PublicKeyCredential: { isConditionalMediationAvailable: async () => true },
|
|
731
|
+
};
|
|
732
|
+
const client = fakeClient();
|
|
733
|
+
const { result, onSignedIn } = renderController({ client });
|
|
734
|
+
await waitFor(() => expect(onSignedIn).toHaveBeenCalledTimes(1));
|
|
735
|
+
expect(client.calls.passkey).toEqual([{ autoFill: true }]);
|
|
736
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "passkey", user: BOB }]);
|
|
737
|
+
expect(result.current.step).toBe("signedIn");
|
|
738
|
+
});
|
|
739
|
+
it("ends autofill quietly, and skips it when unsupported or turned off", async () => {
|
|
740
|
+
const infoSpy = spyOn(console, "info").mockImplementation(() => { });
|
|
741
|
+
globalWithWindow.window = {
|
|
742
|
+
PublicKeyCredential: { isConditionalMediationAvailable: async () => true },
|
|
743
|
+
};
|
|
744
|
+
const aborted = renderController({
|
|
745
|
+
client: fakeClient({}, { passkey: async () => ({ data: null, error: { code: "ERROR_CEREMONY_ABORTED", status: 400 } }) }),
|
|
746
|
+
});
|
|
747
|
+
await waitForLoginScreen(aborted.result);
|
|
748
|
+
await waitFor(() => expect(infoSpy).toHaveBeenCalled());
|
|
749
|
+
expect(aborted.result.current.screenProps.error).toBeUndefined();
|
|
750
|
+
const turnedOffClient = fakeClient();
|
|
751
|
+
const turnedOff = renderController({ client: turnedOffClient, passkeyAutofill: false });
|
|
752
|
+
await waitForLoginScreen(turnedOff.result);
|
|
753
|
+
expect(turnedOff.result.current.screenProps.passkeyAutofill).toBe(false);
|
|
754
|
+
expect(turnedOffClient.calls.passkey).toEqual([]);
|
|
755
|
+
globalWithWindow.window = {
|
|
756
|
+
PublicKeyCredential: {
|
|
757
|
+
isConditionalMediationAvailable: async () => {
|
|
758
|
+
throw new Error("no");
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
};
|
|
762
|
+
const failing = renderController({ client: fakeClient() });
|
|
763
|
+
await waitForLoginScreen(failing.result);
|
|
764
|
+
await waitFor(() => expect(infoSpy.mock.calls.some(([text]) => String(text).includes("unavailable"))).toBe(true));
|
|
765
|
+
globalWithWindow.window = {};
|
|
766
|
+
const unsupported = fakeClient();
|
|
767
|
+
const noApi = renderController({ client: unsupported });
|
|
768
|
+
await waitForLoginScreen(noApi.result);
|
|
769
|
+
expect(unsupported.calls.passkey).toEqual([]);
|
|
770
|
+
});
|
|
771
|
+
it("finishes a bearer social return before reading the token, and records the provider", async () => {
|
|
772
|
+
const sessionStorage = memoryStorage();
|
|
773
|
+
const localStorage = memoryStorage();
|
|
774
|
+
sessionStorage.values.set("terreno_oauth_handoff_nonce", "nonce-1");
|
|
775
|
+
sessionStorage.values.set("terreno_login_pending_method", "github");
|
|
776
|
+
const replaceState = mock((_state, _title, _url) => { });
|
|
777
|
+
globalWithWindow.window = {
|
|
778
|
+
history: { replaceState, state: null },
|
|
779
|
+
localStorage,
|
|
780
|
+
location: { href: "http://app.test/login?handoff=nonce-1#ott=one-time" },
|
|
781
|
+
sessionStorage,
|
|
782
|
+
};
|
|
783
|
+
const originalFetch = globalThis.fetch;
|
|
784
|
+
const verified = [];
|
|
785
|
+
globalThis.fetch = (async (input, init) => {
|
|
786
|
+
const request = input instanceof Request ? input : new Request(String(input), init);
|
|
787
|
+
if (request.url.includes("/terreno/methods")) {
|
|
788
|
+
return Response.json(METHODS);
|
|
789
|
+
}
|
|
790
|
+
if (request.url.includes("/one-time-token/verify")) {
|
|
791
|
+
verified.push((await request.json()).token);
|
|
792
|
+
return Response.json({ session: { id: "s" }, user: JANE }, { headers: { "set-auth-token": "bearer-1" } });
|
|
793
|
+
}
|
|
794
|
+
if (request.url.includes("/get-session")) {
|
|
795
|
+
const isAuthorized = request.headers.get("authorization") === "Bearer bearer-1";
|
|
796
|
+
return Response.json(isAuthorized ? { session: { id: "s" }, user: JANE } : null);
|
|
797
|
+
}
|
|
798
|
+
return Response.json(null);
|
|
799
|
+
});
|
|
800
|
+
try {
|
|
801
|
+
const client = createBetterAuthClient({
|
|
802
|
+
baseURL: "http://api.test",
|
|
803
|
+
features: { multiSession: true, passkey: true, twoFactor: true },
|
|
804
|
+
scheme: "terreno",
|
|
805
|
+
webAuth: "bearer",
|
|
806
|
+
});
|
|
807
|
+
const store = createStore();
|
|
808
|
+
const onSignedIn = mock((_event) => { });
|
|
809
|
+
renderHook(() => useLoginController({ client, onSignedIn, rememberedAccounts: store }));
|
|
810
|
+
await waitFor(() => expect(onSignedIn).toHaveBeenCalledTimes(1));
|
|
811
|
+
expect(verified).toEqual(["one-time"]);
|
|
812
|
+
expect(localStorage.values.get("terreno_bearer_token")).toBe("bearer-1");
|
|
813
|
+
expect(onSignedIn.mock.calls[0]).toEqual([
|
|
814
|
+
{ method: "github", user: expect.objectContaining({ id: "u1" }) },
|
|
815
|
+
]);
|
|
816
|
+
expect(store.list()[0]).toEqual(expect.objectContaining({ method: "github", userId: "u1" }));
|
|
817
|
+
expect(sessionStorage.values.has("terreno_login_pending_method")).toBe(false);
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
820
|
+
globalThis.fetch = originalFetch;
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
it("returns to the login step with an error when onSignedIn throws", async () => {
|
|
824
|
+
spyOn(console, "error").mockImplementation(() => { });
|
|
825
|
+
let signedInCalls = 0;
|
|
826
|
+
const onSignedIn = async () => {
|
|
827
|
+
signedInCalls += 1;
|
|
828
|
+
throw new Error("navigation failed");
|
|
829
|
+
};
|
|
830
|
+
const { result } = renderController({ client: fakeClient(), onSignedIn });
|
|
831
|
+
await waitForLoginScreen(result);
|
|
832
|
+
await act(async () => {
|
|
833
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
834
|
+
});
|
|
835
|
+
expect(signedInCalls).toBe(1);
|
|
836
|
+
expect(result.current.step).toBe("login");
|
|
837
|
+
expect(result.current.screenProps.error).toBe("Sign in failed. Please try again.");
|
|
838
|
+
});
|
|
839
|
+
it("leaves out the email form, forgot-password and email cards when the server has email and password off", async () => {
|
|
840
|
+
const onForgotPasswordPress = mock(() => { });
|
|
841
|
+
const store = createStore();
|
|
842
|
+
await store.record({ method: "email", userId: JANE.id });
|
|
843
|
+
const { result } = renderController({
|
|
844
|
+
client: fakeClient({ methods: { ...METHODS, emailPassword: false } }),
|
|
845
|
+
onForgotPasswordPress,
|
|
846
|
+
rememberedAccounts: store,
|
|
847
|
+
});
|
|
848
|
+
await waitForLoginScreen(result);
|
|
849
|
+
expect(result.current.isEmailPasswordEnabled).toBe(false);
|
|
850
|
+
expect(result.current.screenProps.onForgotPasswordPress).toBeUndefined();
|
|
851
|
+
await act(async () => {
|
|
852
|
+
await result.current.continueAs({ id: "u1", method: "email" }, "remembered");
|
|
853
|
+
});
|
|
854
|
+
expect(result.current.screenProps.error).toBe("That sign-in method is no longer available. Choose another way to sign in.");
|
|
855
|
+
const on = renderController({ client: fakeClient(), onForgotPasswordPress });
|
|
856
|
+
await waitForLoginScreen(on.result);
|
|
857
|
+
expect(on.result.current.isEmailPasswordEnabled).toBe(true);
|
|
858
|
+
expect(on.result.current.screenProps.onForgotPasswordPress).toBe(onForgotPasswordPress);
|
|
859
|
+
});
|
|
860
|
+
it("treats a remembered passkey card as unavailable when passkeys are off", async () => {
|
|
861
|
+
const client = fakeClient({ methods: { ...METHODS, passkey: false } });
|
|
862
|
+
const { result } = renderController({ client });
|
|
863
|
+
await waitForLoginScreen(result);
|
|
864
|
+
await act(async () => {
|
|
865
|
+
await result.current.continueAs({ id: "u2", method: "passkey" }, "remembered");
|
|
866
|
+
});
|
|
867
|
+
expect(client.calls.passkey).toEqual([]);
|
|
868
|
+
expect(result.current.screenProps.error).toBe("That sign-in method is no longer available. Choose another way to sign in.");
|
|
869
|
+
});
|
|
870
|
+
it("clears a pending social provider when another sign-in method runs", async () => {
|
|
871
|
+
const values = new Map([["terreno_login_pending_method", "github"]]);
|
|
872
|
+
globalWithWindow.window = {
|
|
873
|
+
sessionStorage: {
|
|
874
|
+
getItem: (key) => values.get(key) ?? null,
|
|
875
|
+
removeItem: (key) => {
|
|
876
|
+
values.delete(key);
|
|
877
|
+
},
|
|
878
|
+
setItem: (key, value) => {
|
|
879
|
+
values.set(key, value);
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
};
|
|
883
|
+
// A live-session check that found nothing already drops a stale entry.
|
|
884
|
+
const { result, onSignedIn } = renderController({ client: fakeClient() });
|
|
885
|
+
await waitForLoginScreen(result);
|
|
886
|
+
expect(values.has("terreno_login_pending_method")).toBe(false);
|
|
887
|
+
values.set("terreno_login_pending_method", "github");
|
|
888
|
+
await act(async () => {
|
|
889
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
890
|
+
});
|
|
891
|
+
expect(values.has("terreno_login_pending_method")).toBe(false);
|
|
892
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "email", user: JANE }]);
|
|
893
|
+
});
|
|
894
|
+
it("drops passkey autofill that resolves after the screen unmounts", async () => {
|
|
895
|
+
globalWithWindow.window = {
|
|
896
|
+
PublicKeyCredential: { isConditionalMediationAvailable: async () => true },
|
|
897
|
+
};
|
|
898
|
+
let resolvePasskey = () => { };
|
|
899
|
+
const client = fakeClient({}, {
|
|
900
|
+
passkey: () => new Promise((resolve) => {
|
|
901
|
+
resolvePasskey = resolve;
|
|
902
|
+
}),
|
|
903
|
+
});
|
|
904
|
+
const { unmount, onSignedIn } = renderController({ client });
|
|
905
|
+
await waitFor(() => expect(client.calls.passkey).toEqual([{ autoFill: true }]));
|
|
906
|
+
unmount();
|
|
907
|
+
await act(async () => {
|
|
908
|
+
resolvePasskey({ data: { user: BOB }, error: null });
|
|
909
|
+
await Promise.resolve();
|
|
910
|
+
});
|
|
911
|
+
expect(onSignedIn).not.toHaveBeenCalled();
|
|
912
|
+
});
|
|
913
|
+
it("restarts passkey autofill when the screen returns to the login step", async () => {
|
|
914
|
+
globalWithWindow.window = {
|
|
915
|
+
PublicKeyCredential: { isConditionalMediationAvailable: async () => true },
|
|
916
|
+
};
|
|
917
|
+
const client = fakeClient({}, {
|
|
918
|
+
email: async () => ({
|
|
919
|
+
data: { twoFactorMethods: ["totp"], twoFactorRedirect: true },
|
|
920
|
+
error: null,
|
|
921
|
+
}),
|
|
922
|
+
// Autofill waits until the browser offers a passkey, which never happens here.
|
|
923
|
+
passkey: () => new Promise(() => { }),
|
|
924
|
+
});
|
|
925
|
+
const { result } = renderController({ client });
|
|
926
|
+
await waitFor(() => expect(client.calls.passkey).toHaveLength(1));
|
|
927
|
+
await act(async () => {
|
|
928
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "pw" });
|
|
929
|
+
});
|
|
930
|
+
expect(result.current.step).toBe("twoFactor");
|
|
931
|
+
act(() => result.current.twoFactor.onCancel());
|
|
932
|
+
await waitFor(() => expect(client.calls.passkey).toHaveLength(2));
|
|
933
|
+
expect(client.calls.passkey).toEqual([{ autoFill: true }, { autoFill: true }]);
|
|
934
|
+
});
|
|
935
|
+
it("switches to a device session when its card is pressed", async () => {
|
|
936
|
+
const store = createStore();
|
|
937
|
+
await store.record({ method: "github", userId: BOB.id });
|
|
938
|
+
const client = fakeClient({ deviceSessions: [{ session: { token: "tok-bob" }, user: BOB }] });
|
|
939
|
+
const { result, onSignedIn } = renderController({ client, rememberedAccounts: store });
|
|
940
|
+
await waitForLoginScreen(result);
|
|
941
|
+
await waitFor(() => expect(result.current.screenProps.currentSessions).toHaveLength(1));
|
|
942
|
+
const [card] = result.current.screenProps.currentSessions ?? [];
|
|
943
|
+
await act(async () => {
|
|
944
|
+
await result.current.screenProps.onContinue(card, "session");
|
|
945
|
+
});
|
|
946
|
+
expect(client.calls.setActive).toEqual([{ sessionToken: "tok-bob" }]);
|
|
947
|
+
expect(onSignedIn.mock.calls[0]).toEqual([{ method: "github", user: BOB }]);
|
|
948
|
+
});
|
|
949
|
+
it("reports a refused, empty, or thrown session switch", async () => {
|
|
950
|
+
spyOn(console, "error").mockImplementation(() => { });
|
|
951
|
+
const account = { id: "tok", method: "email" };
|
|
952
|
+
const refused = renderController({
|
|
953
|
+
client: fakeClient({}, { setActive: async () => ({ data: null, error: { message: "Nope", status: 401 } }) }),
|
|
954
|
+
});
|
|
955
|
+
await waitForLoginScreen(refused.result);
|
|
956
|
+
await act(async () => {
|
|
957
|
+
await refused.result.current.continueAs(account, "session");
|
|
958
|
+
});
|
|
959
|
+
expect(refused.result.current.screenProps.error).toBe("Nope");
|
|
960
|
+
const empty = renderController({ client: fakeClient() });
|
|
961
|
+
await waitForLoginScreen(empty.result);
|
|
962
|
+
await act(async () => {
|
|
963
|
+
await empty.result.current.continueAs(account, "session");
|
|
964
|
+
});
|
|
965
|
+
expect(empty.result.current.screenProps.error).toBe("Sign in failed. Please try again.");
|
|
966
|
+
const throwing = renderController({
|
|
967
|
+
client: fakeClient({}, {
|
|
968
|
+
setActive: async () => {
|
|
969
|
+
throw new Error("x");
|
|
970
|
+
},
|
|
971
|
+
}),
|
|
972
|
+
});
|
|
973
|
+
await waitForLoginScreen(throwing.result);
|
|
974
|
+
await act(async () => {
|
|
975
|
+
await throwing.result.current.continueAs(account, "session");
|
|
976
|
+
});
|
|
977
|
+
expect(throwing.result.current.screenProps.error).toBe("Sign in failed. Please try again.");
|
|
978
|
+
const noPlugin = renderController({ client: fakeClient({}, { withoutMultiSession: true }) });
|
|
979
|
+
await waitForLoginScreen(noPlugin.result);
|
|
980
|
+
await act(async () => {
|
|
981
|
+
await noPlugin.result.current.continueAs(account, "session");
|
|
982
|
+
});
|
|
983
|
+
expect(noPlugin.result.current.screenProps.error).toBeUndefined();
|
|
984
|
+
});
|
|
985
|
+
it("re-authenticates a remembered account with its method", async () => {
|
|
986
|
+
const store = createStore(true);
|
|
987
|
+
const client = fakeClient();
|
|
988
|
+
const { result, onSignedIn } = renderController({ client, rememberedAccounts: store });
|
|
989
|
+
await waitForLoginScreen(result);
|
|
990
|
+
await act(async () => {
|
|
991
|
+
await result.current.continueAs({ id: "u1", method: "google" }, "remembered");
|
|
992
|
+
});
|
|
993
|
+
expect(client.calls.social).toEqual([{ provider: "google" }]);
|
|
994
|
+
await act(async () => {
|
|
995
|
+
await result.current.continueAs({ id: "u2", method: "passkey" }, "remembered");
|
|
996
|
+
});
|
|
997
|
+
expect(client.calls.passkey).toEqual([undefined]);
|
|
998
|
+
expect(onSignedIn).toHaveBeenCalledTimes(2);
|
|
999
|
+
});
|
|
1000
|
+
it("prefills or prompts for the email of a remembered email account", async () => {
|
|
1001
|
+
const { result } = renderController({ client: fakeClient(), initialEmail: "start@example.com" });
|
|
1002
|
+
await waitForLoginScreen(result);
|
|
1003
|
+
expect(result.current.screenProps.initialValues).toEqual({ email: "start@example.com" });
|
|
1004
|
+
await act(async () => {
|
|
1005
|
+
await result.current.continueAs({ email: "j***@e***.com", id: "u1", method: "email", name: "Jane" }, "remembered");
|
|
1006
|
+
});
|
|
1007
|
+
expect(result.current.screenProps.notice).toEqual({
|
|
1008
|
+
text: "Enter your email and password to continue as Jane.",
|
|
1009
|
+
tone: "info",
|
|
1010
|
+
});
|
|
1011
|
+
await act(async () => {
|
|
1012
|
+
await result.current.continueAs({ id: "u1", method: "email" }, "remembered");
|
|
1013
|
+
});
|
|
1014
|
+
expect(result.current.screenProps.notice?.text).toBe("Enter your email and password to continue.");
|
|
1015
|
+
await act(async () => {
|
|
1016
|
+
await result.current.continueAs({ email: "jane@example.com", id: "u1", method: "email" }, "remembered");
|
|
1017
|
+
});
|
|
1018
|
+
expect(result.current.screenProps.initialValues).toEqual({
|
|
1019
|
+
email: "jane@example.com",
|
|
1020
|
+
password: "",
|
|
1021
|
+
});
|
|
1022
|
+
expect(result.current.screenProps.continuingAccount).toEqual({
|
|
1023
|
+
email: "jane@example.com",
|
|
1024
|
+
id: "u1",
|
|
1025
|
+
method: "email",
|
|
1026
|
+
});
|
|
1027
|
+
expect(result.current.screenProps.notice).toBeUndefined();
|
|
1028
|
+
await act(async () => {
|
|
1029
|
+
await result.current.continueAs({ email: "other@example.com", id: "u2", method: "email" }, "remembered");
|
|
1030
|
+
});
|
|
1031
|
+
expect(result.current.screenProps.initialValues).toEqual({
|
|
1032
|
+
email: "other@example.com",
|
|
1033
|
+
password: "",
|
|
1034
|
+
});
|
|
1035
|
+
act(() => result.current.screenProps.onCancelContinue?.());
|
|
1036
|
+
expect(result.current.screenProps.continuingAccount).toBeUndefined();
|
|
1037
|
+
expect(result.current.screenProps.initialValues).toEqual({
|
|
1038
|
+
email: "start@example.com",
|
|
1039
|
+
password: "",
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
it("leaves the password step and clears the typed password when two-factor is cancelled", async () => {
|
|
1043
|
+
const client = fakeClient({}, {
|
|
1044
|
+
email: async () => ({
|
|
1045
|
+
data: { twoFactorMethods: ["totp"], twoFactorRedirect: true },
|
|
1046
|
+
error: null,
|
|
1047
|
+
}),
|
|
1048
|
+
});
|
|
1049
|
+
const { result } = renderController({ client, initialEmail: "start@example.com" });
|
|
1050
|
+
await waitForLoginScreen(result);
|
|
1051
|
+
await act(async () => {
|
|
1052
|
+
await result.current.continueAs({ email: "jane@example.com", id: "u1", method: "email", name: "Jane" }, "remembered");
|
|
1053
|
+
});
|
|
1054
|
+
await act(async () => {
|
|
1055
|
+
await result.current.signInEmail({ email: "jane@example.com", password: "secret" });
|
|
1056
|
+
});
|
|
1057
|
+
expect(result.current.step).toBe("twoFactor");
|
|
1058
|
+
expect(result.current.screenProps.continuingAccount?.email).toBe("jane@example.com");
|
|
1059
|
+
await act(async () => {
|
|
1060
|
+
result.current.twoFactor.onCancel();
|
|
1061
|
+
});
|
|
1062
|
+
expect(result.current.step).toBe("login");
|
|
1063
|
+
expect(result.current.screenProps.continuingAccount).toBeUndefined();
|
|
1064
|
+
expect(result.current.screenProps.initialValues).toEqual({
|
|
1065
|
+
email: "start@example.com",
|
|
1066
|
+
password: "",
|
|
1067
|
+
});
|
|
1068
|
+
});
|
|
1069
|
+
it("explains a remembered method the server no longer offers, and forgets accounts", async () => {
|
|
1070
|
+
const store = createStore();
|
|
1071
|
+
await store.record({ method: "apple", userId: "u9" });
|
|
1072
|
+
const { result } = renderController({ client: fakeClient(), rememberedAccounts: store });
|
|
1073
|
+
await waitForLoginScreen(result);
|
|
1074
|
+
await act(async () => {
|
|
1075
|
+
await result.current.continueAs({ id: "u9", method: "apple" }, "remembered");
|
|
1076
|
+
});
|
|
1077
|
+
expect(result.current.screenProps.error).toBe("That sign-in method is no longer available. Choose another way to sign in.");
|
|
1078
|
+
await act(async () => {
|
|
1079
|
+
await result.current.screenProps.onForget({ id: "u9", method: "apple" });
|
|
1080
|
+
});
|
|
1081
|
+
expect(store.list()).toEqual([]);
|
|
1082
|
+
expect(result.current.screenProps.rememberedAccounts).toEqual([]);
|
|
1083
|
+
});
|
|
1084
|
+
it("keeps working when the device-session list fails or the methods do not load", async () => {
|
|
1085
|
+
const warnSpy = spyOn(console, "warn").mockImplementation(() => { });
|
|
1086
|
+
const client = fakeClient();
|
|
1087
|
+
if (client.multiSession) {
|
|
1088
|
+
client.multiSession.listDeviceSessions = async () => {
|
|
1089
|
+
throw new Error("boom");
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
const { result } = renderController({ client });
|
|
1093
|
+
await waitForLoginScreen(result);
|
|
1094
|
+
await waitFor(() => expect(warnSpy.mock.calls.some(([text]) => String(text).includes("sessions"))).toBe(true));
|
|
1095
|
+
expect(result.current.screenProps.currentSessions).toEqual([]);
|
|
1096
|
+
const noMethods = fakeClient();
|
|
1097
|
+
noMethods.$fetch = async () => ({ data: null, error: { message: "down" } });
|
|
1098
|
+
const offline = renderController({ client: noMethods });
|
|
1099
|
+
await waitForLoginScreen(offline.result, false);
|
|
1100
|
+
expect(offline.result.current.screenProps.oauthProviders).toEqual([]);
|
|
1101
|
+
expect(offline.result.current.screenProps.genericProviders).toEqual([]);
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
describe("recordRememberedSignIn", () => {
|
|
1105
|
+
it("swallows a store failure", async () => {
|
|
1106
|
+
const warnSpy = spyOn(console, "warn").mockImplementation(() => { });
|
|
1107
|
+
const store = createStore();
|
|
1108
|
+
store.record = async () => {
|
|
1109
|
+
throw new Error("disk full");
|
|
1110
|
+
};
|
|
1111
|
+
await recordRememberedSignIn({ method: "email", store, user: JANE });
|
|
1112
|
+
expect(warnSpy).toHaveBeenCalled();
|
|
1113
|
+
warnSpy.mockRestore();
|
|
1114
|
+
});
|
|
1115
|
+
});
|
|
1116
|
+
//# sourceMappingURL=useLoginController.isolated.js.map
|