@djangocfg/api 2.1.322 → 2.1.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth-server.cjs +4265 -1169
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +4265 -1159
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +4150 -3053
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +158 -209
- package/dist/auth.d.ts +158 -209
- package/dist/auth.mjs +4139 -3042
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +3932 -4031
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +2408 -2671
- package/dist/clients.d.ts +2408 -2671
- package/dist/clients.mjs +3945 -4038
- package/dist/clients.mjs.map +1 -1
- package/dist/index.cjs +4214 -2713
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2758 -1828
- package/dist/index.d.ts +2758 -1828
- package/dist/index.mjs +4183 -2676
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
- package/src/_api/generated/_shared/errors.ts +70 -0
- package/src/_api/generated/_shared/index.ts +25 -0
- package/src/_api/generated/_shared/logger.ts +123 -0
- package/src/_api/generated/_shared/storage.ts +83 -0
- package/src/_api/generated/_shared/validation-events.ts +52 -0
- package/src/_api/generated/cfg_accounts/api.ts +187 -0
- package/src/_api/generated/cfg_accounts/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_accounts/client/index.ts +25 -0
- package/src/_api/generated/cfg_accounts/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_accounts/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_accounts/client.gen.ts +16 -0
- package/src/_api/generated/cfg_accounts/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_accounts/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_accounts/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_accounts/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_accounts/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_accounts/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_accounts/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_accounts/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_accounts/events.ts +198 -0
- package/src/_api/generated/cfg_accounts/hooks/index.ts +18 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthDisconnectCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpRequestCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileAvatarCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileDeleteCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdateUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsTokenRefreshCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/index.ts +26 -335
- package/src/_api/generated/cfg_accounts/schemas/AccountDeleteResponse.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/CentrifugoToken.ts +14 -0
- package/src/_api/generated/cfg_accounts/schemas/CfgUserUpdateRequest.ts +16 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeResponse.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthConnection.ts +19 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthError.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthProvidersResponse.ts +11 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthTokenResponse.ts +18 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPErrorResponse.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPRequestResponse.ts +11 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPVerifyRequest.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPVerifyResponse.ts +17 -0
- package/src/_api/generated/cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts +16 -0
- package/src/_api/generated/cfg_accounts/schemas/ProviderEnum.ts +9 -0
- package/src/_api/generated/cfg_accounts/schemas/TokenRefresh.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/TokenRefreshRequest.ts +11 -0
- package/src/_api/generated/cfg_accounts/{_utils/schemas/User.schema.ts → schemas/User.ts} +8 -16
- package/src/_api/generated/cfg_accounts/schemas/index.ts +24 -0
- package/src/_api/generated/cfg_accounts/sdk.gen.ts +796 -0
- package/src/_api/generated/cfg_accounts/types.gen.ts +764 -0
- package/src/_api/generated/cfg_centrifugo/api.ts +164 -0
- package/src/_api/generated/cfg_centrifugo/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_centrifugo/client/index.ts +25 -0
- package/src/_api/generated/cfg_centrifugo/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_centrifugo/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_centrifugo/client.gen.ts +16 -0
- package/src/_api/generated/cfg_centrifugo/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_centrifugo/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_centrifugo/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_centrifugo/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_centrifugo/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_centrifugo/events.ts +198 -0
- package/src/_api/generated/cfg_centrifugo/hooks/index.ts +4 -0
- package/src/_api/generated/cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +26 -0
- package/src/_api/generated/cfg_centrifugo/index.ts +26 -313
- package/src/_api/generated/cfg_centrifugo/schemas/ConnectionTokenResponse.ts +14 -0
- package/src/_api/generated/cfg_centrifugo/schemas/index.ts +4 -0
- package/src/_api/generated/cfg_centrifugo/sdk.gen.ts +64 -0
- package/src/_api/generated/cfg_centrifugo/types.gen.ts +61 -0
- package/src/_api/generated/cfg_totp/api.ts +181 -0
- package/src/_api/generated/cfg_totp/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_totp/client/index.ts +25 -0
- package/src/_api/generated/cfg_totp/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_totp/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_totp/client.gen.ts +16 -0
- package/src/_api/generated/cfg_totp/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_totp/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_totp/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_totp/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_totp/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_totp/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_totp/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_totp/events.ts +198 -0
- package/src/_api/generated/cfg_totp/hooks/index.ts +12 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +26 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesDestroy.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +26 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDisableCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupConfirmCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyBackupCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/index.ts +26 -342
- package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateResponse.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/BackupCodesStatus.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/ConfirmSetupRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/ConfirmSetupResponse.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceList.ts +18 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceListResponse.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceListStatusEnum.ts +9 -0
- package/src/_api/generated/cfg_totp/schemas/DisableRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/SetupRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/SetupResponse.ts +15 -0
- package/src/_api/generated/cfg_totp/{_utils/schemas/TotpVerifyUser.schema.ts → schemas/TotpVerifyUser.ts} +7 -15
- package/src/_api/generated/cfg_totp/schemas/VerifyBackupRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/VerifyRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/VerifyResponse.ts +17 -0
- package/src/_api/generated/cfg_totp/schemas/index.ts +18 -0
- package/src/_api/generated/cfg_totp/sdk.gen.ts +432 -0
- package/src/_api/generated/cfg_totp/types.gen.ts +479 -0
- package/src/_api/generated/index.ts +30 -0
- package/src/_api/index.ts +5 -23
- package/src/auth/context/AccountsContext.tsx +58 -89
- package/src/auth/context/AuthContext.tsx +3 -3
- package/src/auth/context/index.ts +2 -2
- package/src/auth/hooks/useDeleteAccount.ts +2 -1
- package/src/auth/hooks/useGithubAuth.ts +12 -11
- package/src/auth/hooks/useTokenRefresh.ts +6 -4
- package/src/auth/hooks/useTwoFactor.ts +14 -8
- package/src/auth/hooks/useTwoFactorSetup.ts +8 -5
- package/src/auth/hooks/useTwoFactorStatus.ts +3 -2
- package/src/auth/middlewares/tokenRefresh.ts +6 -4
- package/src/clients.ts +14 -51
- package/src/index.ts +15 -57
- package/src/server.ts +25 -23
- package/src/_api/BaseClient.ts +0 -22
- package/src/_api/generated/cfg_accounts/CLAUDE.md +0 -86
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts.ts +0 -154
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts +0 -95
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts +0 -285
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__user_profile.ts +0 -440
- package/src/_api/generated/cfg_accounts/_utils/fetchers/index.ts +0 -33
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts.ts +0 -64
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__auth.ts +0 -44
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__oauth.ts +0 -114
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__user_profile.ts +0 -152
- package/src/_api/generated/cfg_accounts/_utils/hooks/index.ts +0 -33
- package/src/_api/generated/cfg_accounts/_utils/schemas/AccountDeleteResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +0 -22
- package/src/_api/generated/cfg_accounts/_utils/schemas/CfgAccountsProfileAvatarCreateRequest.schema.ts +0 -15
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +0 -21
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +0 -27
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthDisconnectRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthError.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +0 -19
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +0 -46
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts +0 -41
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts +0 -19
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +0 -21
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts +0 -45
- package/src/_api/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts +0 -24
- package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefresh.schema.ts +0 -16
- package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefreshRequest.schema.ts +0 -15
- package/src/_api/generated/cfg_accounts/_utils/schemas/UserProfileUpdateRequest.schema.ts +0 -24
- package/src/_api/generated/cfg_accounts/_utils/schemas/index.ts +0 -41
- package/src/_api/generated/cfg_accounts/accounts/client.ts +0 -34
- package/src/_api/generated/cfg_accounts/accounts/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts/models.ts +0 -127
- package/src/_api/generated/cfg_accounts/accounts__auth/client.ts +0 -23
- package/src/_api/generated/cfg_accounts/accounts__auth/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__auth/models.ts +0 -19
- package/src/_api/generated/cfg_accounts/accounts__oauth/client.ts +0 -67
- package/src/_api/generated/cfg_accounts/accounts__oauth/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +0 -127
- package/src/_api/generated/cfg_accounts/accounts__user_profile/client.ts +0 -94
- package/src/_api/generated/cfg_accounts/accounts__user_profile/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +0 -98
- package/src/_api/generated/cfg_accounts/api-instance.ts +0 -181
- package/src/_api/generated/cfg_accounts/client.ts +0 -339
- package/src/_api/generated/cfg_accounts/enums.ts +0 -10
- package/src/_api/generated/cfg_accounts/errors.ts +0 -123
- package/src/_api/generated/cfg_accounts/http.ts +0 -160
- package/src/_api/generated/cfg_accounts/logger.ts +0 -261
- package/src/_api/generated/cfg_accounts/retry.ts +0 -177
- package/src/_api/generated/cfg_accounts/schema.json +0 -1576
- package/src/_api/generated/cfg_accounts/storage.ts +0 -163
- package/src/_api/generated/cfg_accounts/validation-events.ts +0 -135
- package/src/_api/generated/cfg_centrifugo/CLAUDE.md +0 -60
- package/src/_api/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_auth.ts +0 -94
- package/src/_api/generated/cfg_centrifugo/_utils/fetchers/index.ts +0 -30
- package/src/_api/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_auth.ts +0 -39
- package/src/_api/generated/cfg_centrifugo/_utils/hooks/index.ts +0 -30
- package/src/_api/generated/cfg_centrifugo/_utils/schemas/ConnectionTokenResponse.schema.ts +0 -22
- package/src/_api/generated/cfg_centrifugo/_utils/schemas/index.ts +0 -21
- package/src/_api/generated/cfg_centrifugo/api-instance.ts +0 -181
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/client.ts +0 -27
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/index.ts +0 -4
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/models.ts +0 -18
- package/src/_api/generated/cfg_centrifugo/client.ts +0 -330
- package/src/_api/generated/cfg_centrifugo/errors.ts +0 -123
- package/src/_api/generated/cfg_centrifugo/http.ts +0 -160
- package/src/_api/generated/cfg_centrifugo/logger.ts +0 -261
- package/src/_api/generated/cfg_centrifugo/retry.ts +0 -177
- package/src/_api/generated/cfg_centrifugo/schema.json +0 -118
- package/src/_api/generated/cfg_centrifugo/storage.ts +0 -163
- package/src/_api/generated/cfg_centrifugo/validation-events.ts +0 -135
- package/src/_api/generated/cfg_totp/CLAUDE.md +0 -83
- package/src/_api/generated/cfg_totp/_utils/fetchers/index.ts +0 -34
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp.ts +0 -50
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +0 -153
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_management.ts +0 -109
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_setup.ts +0 -154
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_verification.ts +0 -153
- package/src/_api/generated/cfg_totp/_utils/hooks/index.ts +0 -34
- package/src/_api/generated/cfg_totp/_utils/hooks/totp.ts +0 -43
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +0 -60
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_management.ts +0 -59
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_setup.ts +0 -64
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_verification.ts +0 -63
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +0 -26
- package/src/_api/generated/cfg_totp/_utils/schemas/DeviceListResponse.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +0 -23
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +0 -25
- package/src/_api/generated/cfg_totp/_utils/schemas/index.ts +0 -34
- package/src/_api/generated/cfg_totp/api-instance.ts +0 -181
- package/src/_api/generated/cfg_totp/client.ts +0 -342
- package/src/_api/generated/cfg_totp/enums.ts +0 -13
- package/src/_api/generated/cfg_totp/errors.ts +0 -123
- package/src/_api/generated/cfg_totp/http.ts +0 -160
- package/src/_api/generated/cfg_totp/logger.ts +0 -261
- package/src/_api/generated/cfg_totp/retry.ts +0 -177
- package/src/_api/generated/cfg_totp/schema.json +0 -910
- package/src/_api/generated/cfg_totp/storage.ts +0 -163
- package/src/_api/generated/cfg_totp/totp/client.ts +0 -24
- package/src/_api/generated/cfg_totp/totp/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp/models.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__backup_codes/client.ts +0 -32
- package/src/_api/generated/cfg_totp/totp__backup_codes/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +0 -38
- package/src/_api/generated/cfg_totp/totp__totp_management/client.ts +0 -31
- package/src/_api/generated/cfg_totp/totp__totp_management/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_management/models.ts +0 -46
- package/src/_api/generated/cfg_totp/totp__totp_setup/client.ts +0 -33
- package/src/_api/generated/cfg_totp/totp__totp_setup/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +0 -55
- package/src/_api/generated/cfg_totp/totp__totp_verification/client.ts +0 -33
- package/src/_api/generated/cfg_totp/totp__totp_verification/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_verification/models.ts +0 -74
- package/src/_api/generated/cfg_totp/validation-events.ts +0 -135
- package/src/hooks/accounts.ts +0 -8
- package/src/hooks/index.ts +0 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Accounts Context
|
|
3
3
|
*
|
|
4
|
-
* Manages user authentication and profile operations using generated SWR hooks
|
|
4
|
+
* Manages user authentication and profile operations using generated SWR hooks.
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
7
|
* - OTP-based authentication
|
|
@@ -17,87 +17,72 @@ import {
|
|
|
17
17
|
createContext, ReactNode, useCallback, useContext, useEffect, useRef, useState
|
|
18
18
|
} from 'react';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
// Import schema
|
|
23
|
-
import { PatchedUserProfileUpdateRequestSchema } from '../../_api/generated/cfg_accounts';
|
|
24
|
-
// Import hooks from generated API hooks
|
|
20
|
+
import { cfgAccountsApi } from '../../';
|
|
21
|
+
import { Accounts, Auth, UserProfile } from '../../_api/generated/cfg_accounts/sdk.gen';
|
|
25
22
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
useCfgAccountsOtpRequestCreate,
|
|
24
|
+
useCfgAccountsOtpVerifyCreate,
|
|
25
|
+
useCfgAccountsProfileAvatarCreate,
|
|
26
|
+
useCfgAccountsProfilePartialUpdate,
|
|
27
|
+
useCfgAccountsProfileUpdateUpdate,
|
|
28
|
+
useCfgAccountsTokenRefreshCreate,
|
|
29
|
+
} from '../../_api/generated/cfg_accounts/hooks';
|
|
30
|
+
import { PatchedCfgUserUpdateRequestSchema } from '../../_api/generated/cfg_accounts/schemas';
|
|
30
31
|
import { clearProfileCache, getCachedProfile, setCachedProfile } from '../hooks/useProfileCache';
|
|
31
32
|
import { authLogger } from '../utils/logger';
|
|
32
33
|
|
|
33
|
-
// Import types from generated API
|
|
34
34
|
import type {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} from '../../_api/generated/cfg_accounts';
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
export type {
|
|
35
|
+
User,
|
|
36
|
+
CfgUserUpdateRequest,
|
|
37
|
+
PatchedCfgUserUpdateRequest,
|
|
38
|
+
OtpRequestRequest,
|
|
39
|
+
OtpVerifyRequest,
|
|
40
|
+
OtpRequestResponse,
|
|
41
|
+
OtpVerifyResponse,
|
|
42
|
+
TokenRefresh,
|
|
43
|
+
TokenRefreshRequest,
|
|
44
|
+
} from '../../_api/generated/cfg_accounts/types.gen';
|
|
45
|
+
|
|
46
|
+
export { PatchedCfgUserUpdateRequestSchema };
|
|
47
|
+
export type { PatchedCfgUserUpdateRequest, User, CfgUserUpdateRequest as UserProfileUpdateRequest };
|
|
48
48
|
|
|
49
49
|
// ─────────────────────────────────────────────────────────────────────────
|
|
50
50
|
// Context Type
|
|
51
51
|
// ─────────────────────────────────────────────────────────────────────────
|
|
52
52
|
|
|
53
53
|
export interface AccountsContextValue {
|
|
54
|
-
// Current user profile
|
|
55
54
|
profile?: User;
|
|
56
55
|
isLoadingProfile: boolean;
|
|
57
56
|
profileError: Error | null;
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
partialUpdateProfile: (data: PatchedUserProfileUpdateRequest) => Promise<User>;
|
|
58
|
+
updateProfile: (data: CfgUserUpdateRequest) => Promise<User>;
|
|
59
|
+
partialUpdateProfile: (data: PatchedCfgUserUpdateRequest) => Promise<User>;
|
|
62
60
|
uploadAvatar: (avatar: File | Blob) => Promise<User>;
|
|
63
61
|
refreshProfile: (options?: { callerId?: string; force?: boolean }) => Promise<User | undefined>;
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
verifyOTP: (data: OTPVerifyRequest) => Promise<OTPVerifyResponse>;
|
|
63
|
+
requestOTP: (data: OtpRequestRequest) => Promise<OtpRequestResponse>;
|
|
64
|
+
verifyOTP: (data: OtpVerifyRequest) => Promise<OtpVerifyResponse>;
|
|
68
65
|
refreshToken: (refresh: string) => Promise<TokenRefresh>;
|
|
69
66
|
logout: () => void;
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
73
|
-
// Context
|
|
74
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
75
|
-
|
|
76
69
|
const AccountsContext = createContext<AccountsContextValue | undefined>(undefined);
|
|
77
70
|
|
|
78
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
79
|
-
// Provider Component
|
|
80
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
81
|
-
|
|
82
71
|
interface AccountsProviderProps {
|
|
83
72
|
children: ReactNode;
|
|
84
73
|
}
|
|
85
74
|
|
|
86
75
|
export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
87
|
-
// State management with localStorage cache
|
|
88
76
|
const [profile, setProfile] = useState<User | undefined>(() => {
|
|
89
|
-
|
|
90
|
-
const cached = getCachedProfile();
|
|
77
|
+
const cached = getCachedProfile() as User | null;
|
|
91
78
|
return cached || undefined;
|
|
92
79
|
});
|
|
93
80
|
const [isLoadingProfile, setIsLoadingProfile] = useState(false);
|
|
94
81
|
const [profileError, setProfileError] = useState<Error | null>(null);
|
|
95
82
|
|
|
96
|
-
// Use refs to access current state without adding to dependencies
|
|
97
83
|
const profileRef = useRef<User | undefined>(profile);
|
|
98
84
|
const isLoadingRef = useRef(false);
|
|
99
85
|
|
|
100
|
-
// Keep refs in sync with state
|
|
101
86
|
useEffect(() => {
|
|
102
87
|
profileRef.current = profile;
|
|
103
88
|
}, [profile]);
|
|
@@ -106,21 +91,17 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
106
91
|
isLoadingRef.current = isLoadingProfile;
|
|
107
92
|
}, [isLoadingProfile]);
|
|
108
93
|
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const tokenRefreshMutation = useCreateAccountsTokenRefreshCreate();
|
|
94
|
+
const { trigger: triggerProfileUpdate } = useCfgAccountsProfileUpdateUpdate();
|
|
95
|
+
const { trigger: triggerProfilePartialUpdate } = useCfgAccountsProfilePartialUpdate();
|
|
96
|
+
const { trigger: triggerAvatar } = useCfgAccountsProfileAvatarCreate();
|
|
97
|
+
const { trigger: triggerOtpRequest } = useCfgAccountsOtpRequestCreate();
|
|
98
|
+
const { trigger: triggerOtpVerify } = useCfgAccountsOtpVerifyCreate();
|
|
99
|
+
const { trigger: triggerTokenRefresh } = useCfgAccountsTokenRefreshCreate();
|
|
116
100
|
|
|
117
|
-
// Refresh profile - fetch from API and update cache
|
|
118
101
|
const refreshProfile = useCallback(async (options?: { callerId?: string; force?: boolean }): Promise<User | undefined> => {
|
|
119
102
|
const { callerId, force } = options || {};
|
|
120
|
-
const currentLoading = isLoadingRef.current;
|
|
121
103
|
|
|
122
|
-
|
|
123
|
-
if (currentLoading) {
|
|
104
|
+
if (isLoadingRef.current) {
|
|
124
105
|
authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
|
|
125
106
|
return profileRef.current;
|
|
126
107
|
}
|
|
@@ -130,7 +111,8 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
130
111
|
setProfileError(null);
|
|
131
112
|
try {
|
|
132
113
|
authLogger.debug(`Fetching profile from API (caller: ${callerId}, force: ${force})`);
|
|
133
|
-
const
|
|
114
|
+
const res = await UserProfile.cfgAccountsProfileRetrieve({ throwOnError: true });
|
|
115
|
+
const result = res.data;
|
|
134
116
|
setProfile(result);
|
|
135
117
|
profileRef.current = result;
|
|
136
118
|
setCachedProfile(result);
|
|
@@ -145,48 +127,40 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
145
127
|
}
|
|
146
128
|
}, []);
|
|
147
129
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
await updateMutation(data, apiAccounts);
|
|
130
|
+
const updateProfile = async (data: CfgUserUpdateRequest): Promise<User> => {
|
|
131
|
+
await triggerProfileUpdate({ body: data });
|
|
151
132
|
const user = await refreshProfile({ callerId: 'updateProfile', force: true });
|
|
152
133
|
return user as User;
|
|
153
134
|
};
|
|
154
135
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await partialUpdateMutation(data, apiAccounts);
|
|
136
|
+
const partialUpdateProfile = async (data: PatchedCfgUserUpdateRequest): Promise<User> => {
|
|
137
|
+
await triggerProfilePartialUpdate({ body: data });
|
|
158
138
|
const user = await refreshProfile({ callerId: 'partialUpdateProfile', force: true });
|
|
159
139
|
return user as User;
|
|
160
140
|
};
|
|
161
141
|
|
|
162
|
-
// Upload avatar - then reload from API
|
|
163
142
|
const uploadAvatar = async (avatar: File | Blob): Promise<User> => {
|
|
164
|
-
await
|
|
143
|
+
await triggerAvatar({ body: { avatar } });
|
|
165
144
|
const user = await refreshProfile({ callerId: 'uploadAvatar', force: true });
|
|
166
145
|
return user as User;
|
|
167
146
|
};
|
|
168
147
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return result as OTPRequestResponse;
|
|
148
|
+
const requestOTP = async (data: OtpRequestRequest): Promise<OtpRequestResponse> => {
|
|
149
|
+
const result = await triggerOtpRequest({ body: data });
|
|
150
|
+
return result as OtpRequestResponse;
|
|
173
151
|
};
|
|
174
152
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const result = await otpVerifyMutation(data, apiAccounts);
|
|
153
|
+
const verifyOTP = async (data: OtpVerifyRequest): Promise<OtpVerifyResponse> => {
|
|
154
|
+
const result = (await triggerOtpVerify({ body: data })) as OtpVerifyResponse;
|
|
178
155
|
|
|
179
|
-
// Check if 2FA is required - don't save tokens yet
|
|
180
156
|
if (result.requires_2fa && result.session_id) {
|
|
181
157
|
authLogger.info('2FA required, session:', result.session_id);
|
|
182
|
-
|
|
183
|
-
return result as OTPVerifyResponse;
|
|
158
|
+
return result;
|
|
184
159
|
}
|
|
185
160
|
|
|
186
|
-
// Normal flow - save tokens after successful verification
|
|
187
161
|
if (result.access && result.refresh) {
|
|
188
|
-
|
|
189
|
-
|
|
162
|
+
cfgAccountsApi.setToken(result.access);
|
|
163
|
+
cfgAccountsApi.setRefreshToken(result.refresh);
|
|
190
164
|
try {
|
|
191
165
|
await refreshProfile({ callerId: 'verifyOTP', force: true });
|
|
192
166
|
} catch (profileError) {
|
|
@@ -194,24 +168,23 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
194
168
|
}
|
|
195
169
|
}
|
|
196
170
|
|
|
197
|
-
return result
|
|
171
|
+
return result;
|
|
198
172
|
};
|
|
199
173
|
|
|
200
|
-
// Refresh token
|
|
201
174
|
const refreshToken = async (refresh: string): Promise<TokenRefresh> => {
|
|
202
|
-
const
|
|
175
|
+
const body: TokenRefreshRequest = { refresh };
|
|
176
|
+
const result = (await triggerTokenRefresh({ body })) as TokenRefresh;
|
|
203
177
|
|
|
204
|
-
// Automatically save new access token
|
|
205
178
|
if (result.access) {
|
|
206
|
-
|
|
179
|
+
cfgAccountsApi.setToken(result.access);
|
|
180
|
+
cfgAccountsApi.setRefreshToken(refresh);
|
|
207
181
|
}
|
|
208
182
|
|
|
209
|
-
return result
|
|
183
|
+
return result;
|
|
210
184
|
};
|
|
211
185
|
|
|
212
|
-
// Logout - clear tokens, profile state, and cache
|
|
213
186
|
const logout = useCallback(() => {
|
|
214
|
-
|
|
187
|
+
cfgAccountsApi.clearToken();
|
|
215
188
|
setProfile(undefined);
|
|
216
189
|
setProfileError(null);
|
|
217
190
|
clearProfileCache();
|
|
@@ -238,10 +211,6 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
238
211
|
);
|
|
239
212
|
}
|
|
240
213
|
|
|
241
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
242
|
-
// Hook
|
|
243
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
244
|
-
|
|
245
214
|
export function useAccountsContext(): AccountsContextValue {
|
|
246
215
|
const context = useContext(AccountsContext);
|
|
247
216
|
if (!context) {
|
|
@@ -11,7 +11,7 @@ import { SWRConfig } from 'swr';
|
|
|
11
11
|
import { useCfgRouter, useLocalStorage, useQueryParams } from '../hooks';
|
|
12
12
|
|
|
13
13
|
import { api as apiAccounts } from '../../';
|
|
14
|
-
import { APIError } from '../../_api/generated/
|
|
14
|
+
import { APIError } from '../../_api/generated/_shared';
|
|
15
15
|
import { clearProfileCache, getCachedProfile } from '../hooks/useProfileCache';
|
|
16
16
|
import { useAuthRedirectManager } from '../hooks/useAuthRedirect';
|
|
17
17
|
import { useTokenRefresh } from '../hooks/useTokenRefresh';
|
|
@@ -101,7 +101,7 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
|
|
|
101
101
|
// Common function to clear auth state
|
|
102
102
|
const clearAuthState = useCallback((caller: string) => {
|
|
103
103
|
authLogger.info('clearAuthState >> caller', caller);
|
|
104
|
-
apiAccounts.
|
|
104
|
+
apiAccounts.clearToken();
|
|
105
105
|
clearProfileCache(); // Clear profile cache from localStorage
|
|
106
106
|
// Note: user is now managed by AccountsContext, will auto-update
|
|
107
107
|
setInitialized(true);
|
|
@@ -354,7 +354,7 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
|
|
|
354
354
|
const requestOTP = useCallback(
|
|
355
355
|
async (identifier: string, sourceUrl?: string): Promise<{ success: boolean; message: string; statusCode?: number; retryAfter?: number }> => {
|
|
356
356
|
// Clear tokens before requesting OTP
|
|
357
|
-
apiAccounts.
|
|
357
|
+
apiAccounts.clearToken();
|
|
358
358
|
|
|
359
359
|
try {
|
|
360
360
|
const result = await accounts.requestOTP({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AuthProvider, useAuth } from './AuthContext';
|
|
2
2
|
export type { AuthConfig, AuthContextType, AuthProviderProps, UserProfile } from './types';
|
|
3
|
-
export { AccountsProvider, useAccountsContext,
|
|
4
|
-
export type { AccountsContextValue,
|
|
3
|
+
export { AccountsProvider, useAccountsContext, PatchedCfgUserUpdateRequestSchema } from './AccountsContext';
|
|
4
|
+
export type { AccountsContextValue, PatchedCfgUserUpdateRequest } from './AccountsContext';
|
|
@@ -60,7 +60,8 @@ export const useDeleteAccount = (): UseDeleteAccountReturn => {
|
|
|
60
60
|
try {
|
|
61
61
|
authLogger.info('Deleting account...');
|
|
62
62
|
|
|
63
|
-
const
|
|
63
|
+
const result = await apiAccounts.userProfile.cfgAccountsProfileDeleteCreate({ throwOnError: true });
|
|
64
|
+
const response = result.data;
|
|
64
65
|
|
|
65
66
|
if (!response.success) {
|
|
66
67
|
authLogger.error('Failed to delete account:', response.message);
|
|
@@ -69,9 +69,13 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
69
69
|
|
|
70
70
|
// Call API to get authorization URL
|
|
71
71
|
// The API will auto-generate redirect_uri from config if not provided
|
|
72
|
-
const
|
|
73
|
-
|
|
72
|
+
const result = await apiAccounts.oAuth.cfgAccountsOauthGithubAuthorizeCreate({
|
|
73
|
+
body: {
|
|
74
|
+
source_url: sourceUrl || (typeof window !== 'undefined' ? window.location.href : ''),
|
|
75
|
+
},
|
|
76
|
+
throwOnError: true,
|
|
74
77
|
});
|
|
78
|
+
const response = result.data;
|
|
75
79
|
|
|
76
80
|
if (!response.authorization_url) {
|
|
77
81
|
throw new Error('Failed to get authorization URL');
|
|
@@ -79,13 +83,11 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
79
83
|
|
|
80
84
|
authLogger.info('Redirecting to GitHub...', response.authorization_url);
|
|
81
85
|
|
|
82
|
-
// Store state in sessionStorage for verification on callback
|
|
83
86
|
if (typeof window !== 'undefined') {
|
|
84
87
|
sessionStorage.setItem('oauth_state', response.state);
|
|
85
88
|
sessionStorage.setItem('oauth_provider', 'github');
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
// Redirect to GitHub
|
|
89
91
|
window.location.href = response.authorization_url;
|
|
90
92
|
|
|
91
93
|
} catch (err) {
|
|
@@ -128,12 +130,11 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
128
130
|
sessionStorage.removeItem('oauth_provider');
|
|
129
131
|
}
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
code,
|
|
135
|
-
state,
|
|
133
|
+
const result = await apiAccounts.oAuth.cfgAccountsOauthGithubCallbackCreate({
|
|
134
|
+
body: { code, state },
|
|
135
|
+
throwOnError: true,
|
|
136
136
|
});
|
|
137
|
+
const response = result.data;
|
|
137
138
|
|
|
138
139
|
// Check if 2FA is required
|
|
139
140
|
if (response.requires_2fa && response.session_id) {
|
|
@@ -156,8 +157,8 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
156
157
|
|
|
157
158
|
authLogger.info('GitHub OAuth successful, user:', response.user);
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
apiAccounts.
|
|
160
|
+
apiAccounts.setToken(response.access);
|
|
161
|
+
apiAccounts.setRefreshToken(response.refresh);
|
|
161
162
|
|
|
162
163
|
// Track successful OAuth
|
|
163
164
|
Analytics.event(AnalyticsEvent.AUTH_LOGIN_SUCCESS, {
|
|
@@ -77,17 +77,19 @@ export function useTokenRefresh(options: UseTokenRefreshOptions = {}) {
|
|
|
77
77
|
|
|
78
78
|
try {
|
|
79
79
|
// Use generated API client with correct URL (/cfg/accounts/token/refresh/)
|
|
80
|
-
const result = await apiAccounts.auth.
|
|
81
|
-
refresh: refreshTokenValue,
|
|
80
|
+
const result = await apiAccounts.auth.cfgAccountsTokenRefreshCreate({
|
|
81
|
+
body: { refresh: refreshTokenValue },
|
|
82
|
+
throwOnError: true,
|
|
82
83
|
});
|
|
83
84
|
|
|
84
|
-
const newAccessToken = result.access;
|
|
85
|
+
const newAccessToken = result.data.access;
|
|
85
86
|
|
|
86
87
|
if (!newAccessToken) {
|
|
87
88
|
throw new Error('No access token in refresh response');
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
apiAccounts.setToken(newAccessToken
|
|
91
|
+
apiAccounts.setToken(newAccessToken);
|
|
92
|
+
apiAccounts.setRefreshToken(refreshTokenValue);
|
|
91
93
|
authLogger.info('Token refreshed successfully');
|
|
92
94
|
|
|
93
95
|
onRefresh?.(newAccessToken);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { apiAccounts, apiTotp } from '../../clients';
|
|
6
|
-
import { APIError } from '../../_api/generated/
|
|
6
|
+
import { APIError } from '../../_api/generated/_shared';
|
|
7
7
|
import { Analytics, AnalyticsCategory, AnalyticsEvent } from '../utils/analytics';
|
|
8
8
|
import { authLogger } from '../utils/logger';
|
|
9
9
|
import { useCfgRouter } from './useCfgRouter';
|
|
@@ -88,7 +88,8 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
88
88
|
remaining_backup_codes?: number;
|
|
89
89
|
}) => {
|
|
90
90
|
// Save tokens
|
|
91
|
-
apiAccounts.setToken(response.access_token
|
|
91
|
+
apiAccounts.setToken(response.access_token);
|
|
92
|
+
apiAccounts.setRefreshToken(response.refresh_token);
|
|
92
93
|
|
|
93
94
|
// Set warning if any
|
|
94
95
|
if (response.warning) {
|
|
@@ -146,10 +147,11 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
146
147
|
try {
|
|
147
148
|
authLogger.info('Verifying TOTP code...');
|
|
148
149
|
|
|
149
|
-
const
|
|
150
|
-
session_id: sessionId,
|
|
151
|
-
|
|
150
|
+
const result = await apiTotp.totpVerification.cfgTotpVerifyCreate({
|
|
151
|
+
body: { session_id: sessionId, code },
|
|
152
|
+
throwOnError: true,
|
|
152
153
|
});
|
|
154
|
+
const response = result.data;
|
|
153
155
|
|
|
154
156
|
if (!response.access_token || !response.refresh_token) {
|
|
155
157
|
throw new Error('Invalid response from 2FA verification');
|
|
@@ -205,10 +207,14 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
205
207
|
try {
|
|
206
208
|
authLogger.info('Verifying backup code...');
|
|
207
209
|
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
const result = await apiTotp.totpVerification.cfgTotpVerifyBackupCreate({
|
|
211
|
+
body: {
|
|
212
|
+
session_id: sessionId,
|
|
213
|
+
backup_code: backupCode.replace(/\s+/g, ''),
|
|
214
|
+
},
|
|
215
|
+
throwOnError: true,
|
|
211
216
|
});
|
|
217
|
+
const response = result.data;
|
|
212
218
|
|
|
213
219
|
if (!response.access_token || !response.refresh_token) {
|
|
214
220
|
throw new Error('Invalid response from backup code verification');
|
|
@@ -115,9 +115,11 @@ export const useTwoFactorSetup = (options: UseTwoFactorSetupOptions = {}): UseTw
|
|
|
115
115
|
try {
|
|
116
116
|
authLogger.info('Starting 2FA setup...');
|
|
117
117
|
|
|
118
|
-
const
|
|
119
|
-
device_name: deviceName,
|
|
118
|
+
const result = await apiTotp.totpSetup.cfgTotpSetupCreate({
|
|
119
|
+
body: { device_name: deviceName },
|
|
120
|
+
throwOnError: true,
|
|
120
121
|
});
|
|
122
|
+
const response = result.data;
|
|
121
123
|
|
|
122
124
|
const data: TwoFactorSetupData = {
|
|
123
125
|
deviceId: response.device_id,
|
|
@@ -169,10 +171,11 @@ export const useTwoFactorSetup = (options: UseTwoFactorSetupOptions = {}): UseTw
|
|
|
169
171
|
try {
|
|
170
172
|
authLogger.info('Confirming 2FA setup...');
|
|
171
173
|
|
|
172
|
-
const
|
|
173
|
-
device_id: setupData.deviceId,
|
|
174
|
-
|
|
174
|
+
const result = await apiTotp.totpSetup.cfgTotpSetupConfirmCreate({
|
|
175
|
+
body: { device_id: setupData.deviceId, code },
|
|
176
|
+
throwOnError: true,
|
|
175
177
|
});
|
|
178
|
+
const response = result.data;
|
|
176
179
|
|
|
177
180
|
const codes = response.backup_codes;
|
|
178
181
|
setBackupCodes(codes);
|
|
@@ -82,7 +82,8 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
|
|
|
82
82
|
authLogger.info('Fetching 2FA status...');
|
|
83
83
|
|
|
84
84
|
// API returns { devices: [...], has_2fa_enabled: bool }
|
|
85
|
-
const
|
|
85
|
+
const result = await apiTotp.totpManagement.cfgTotpDevicesRetrieve({ throwOnError: true });
|
|
86
|
+
const response = result.data;
|
|
86
87
|
|
|
87
88
|
const mappedDevices: TwoFactorDevice[] = response.devices.map((device) => ({
|
|
88
89
|
id: device.id,
|
|
@@ -121,7 +122,7 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
|
|
|
121
122
|
try {
|
|
122
123
|
authLogger.info('Disabling 2FA...');
|
|
123
124
|
|
|
124
|
-
await apiTotp.
|
|
125
|
+
await apiTotp.totpManagement.cfgTotpDisableCreate({ body: { code }, throwOnError: true });
|
|
125
126
|
|
|
126
127
|
setHas2FAEnabled(false);
|
|
127
128
|
setDevices([]);
|
|
@@ -51,11 +51,12 @@ export async function refreshAccessToken(): Promise<string | null> {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Use generated API client with correct URL (/cfg/accounts/token/refresh/)
|
|
54
|
-
const result = await apiAccounts.auth.
|
|
55
|
-
refresh: refreshToken,
|
|
54
|
+
const result = await apiAccounts.auth.cfgAccountsTokenRefreshCreate({
|
|
55
|
+
body: { refresh: refreshToken },
|
|
56
|
+
throwOnError: true,
|
|
56
57
|
});
|
|
57
58
|
|
|
58
|
-
const newAccessToken = result.access;
|
|
59
|
+
const newAccessToken = result.data.access;
|
|
59
60
|
|
|
60
61
|
if (!newAccessToken) {
|
|
61
62
|
authLogger.error('Token refresh response missing access token');
|
|
@@ -64,7 +65,8 @@ export async function refreshAccessToken(): Promise<string | null> {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// Update tokens in storage
|
|
67
|
-
apiAccounts.setToken(newAccessToken
|
|
68
|
+
apiAccounts.setToken(newAccessToken);
|
|
69
|
+
apiAccounts.setRefreshToken(refreshToken);
|
|
68
70
|
authLogger.info('Token refreshed successfully');
|
|
69
71
|
|
|
70
72
|
onTokenRefreshed(newAccessToken);
|
package/src/clients.ts
CHANGED
|
@@ -1,57 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @djangocfg/api
|
|
2
|
+
* @djangocfg/api/clients — pre-configured per-group API singletons.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Singletons (`cfgAccountsApi`, `cfgTotpApi`, `cfgCentrifugoApi`) live in the
|
|
5
|
+
* generated barrel. This file just re-exports them with the legacy-friendly
|
|
6
|
+
* `apiAccounts` / `apiTotp` / `apiCentrifugo` aliases.
|
|
5
7
|
*
|
|
6
8
|
* Usage:
|
|
7
|
-
* import { apiAccounts
|
|
8
|
-
*
|
|
9
|
+
* import { apiAccounts } from '@djangocfg/api/clients';
|
|
10
|
+
* await apiAccounts.accounts.cfgAccountsLogin({ body });
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const apiUrl = isStaticBuild ? '' : process.env.NEXT_PUBLIC_API_URL || '';
|
|
20
|
-
const storage = new LocalStorageAdapter();
|
|
21
|
-
|
|
22
|
-
export const apiAccounts = new AccountsAPIClass(apiUrl, { storage });
|
|
23
|
-
export const apiTotp = new TotpAPIClass(apiUrl, { storage });
|
|
24
|
-
export const apiCentrifugo = new CentrifugoAPIClass(apiUrl, { storage });
|
|
25
|
-
|
|
26
|
-
// ============================================================================
|
|
27
|
-
// Enums (re-export from accounts)
|
|
28
|
-
// ============================================================================
|
|
29
|
-
export * as Enums from './_api/generated/cfg_accounts/enums';
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// CFG Accounts (primary exports - includes shared types)
|
|
33
|
-
// ============================================================================
|
|
34
|
-
export * from './_api/generated/cfg_accounts/_utils/hooks';
|
|
35
|
-
export * from './_api/generated/cfg_accounts/_utils/fetchers';
|
|
36
|
-
export * from './_api/generated/cfg_accounts/_utils/schemas';
|
|
37
|
-
|
|
38
|
-
// ============================================================================
|
|
39
|
-
// CFG Centrifugo (namespaced to avoid conflicts)
|
|
40
|
-
// ============================================================================
|
|
41
|
-
export * as CentrifugoHooks from './_api/generated/cfg_centrifugo/_utils/hooks';
|
|
42
|
-
export * as CentrifugoFetchers from './_api/generated/cfg_centrifugo/_utils/fetchers';
|
|
43
|
-
export * as CentrifugoTypes from './_api/generated/cfg_centrifugo/_utils/schemas';
|
|
44
|
-
|
|
45
|
-
// ============================================================================
|
|
46
|
-
// CFG TOTP (namespaced to avoid conflicts)
|
|
47
|
-
// ============================================================================
|
|
48
|
-
export * as TotpHooks from './_api/generated/cfg_totp/_utils/hooks';
|
|
49
|
-
export * as TotpFetchers from './_api/generated/cfg_totp/_utils/fetchers';
|
|
50
|
-
export * as TotpTypes from './_api/generated/cfg_totp/_utils/schemas';
|
|
51
|
-
|
|
52
|
-
// ============================================================================
|
|
53
|
-
// API Classes (for creating custom instances)
|
|
54
|
-
// ============================================================================
|
|
55
|
-
export { API as AccountsAPI } from './_api/generated/cfg_accounts';
|
|
56
|
-
export { API as TotpAPI } from './_api/generated/cfg_totp';
|
|
57
|
-
export { API as CentrifugoAPI } from './_api/generated/cfg_centrifugo';
|
|
13
|
+
export {
|
|
14
|
+
cfgAccountsApi as apiAccounts,
|
|
15
|
+
cfgTotpApi as apiTotp,
|
|
16
|
+
cfgCentrifugoApi as apiCentrifugo,
|
|
17
|
+
CfgAccountsAPI as AccountsAPI,
|
|
18
|
+
CfgTotpAPI as TotpAPI,
|
|
19
|
+
CfgCentrifugoAPI as CentrifugoAPI,
|
|
20
|
+
} from './_api/generated';
|