@djangocfg/api 2.1.322 → 2.1.331
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 +1037 -1227
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +1037 -1217
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +2142 -3398
- 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 +2136 -3392
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +1018 -4423
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +151 -2918
- package/dist/clients.d.ts +151 -2918
- package/dist/clients.mjs +1018 -4417
- package/dist/clients.mjs.map +1 -1
- package/dist/index.cjs +2253 -2819
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2408 -1872
- package/dist/index.d.ts +2408 -1872
- package/dist/index.mjs +2235 -2795
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
- package/src/_api/generated/_cfg_accounts/api.ts +120 -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 +25 -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 +25 -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 +25 -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 +29 -0
- 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 → _cfg_accounts/schemas/User.ts} +19 -27
- package/src/_api/generated/_cfg_accounts/schemas/index.ts +24 -0
- package/src/_api/generated/_cfg_accounts/sdk.gen.ts +5 -0
- package/src/_api/generated/_cfg_accounts/types.gen.ts +5 -0
- package/src/_api/generated/_cfg_centrifugo/api.ts +120 -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 +25 -0
- package/src/_api/generated/_cfg_centrifugo/index.ts +29 -0
- 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 +5 -0
- package/src/_api/generated/_cfg_centrifugo/types.gen.ts +5 -0
- package/src/_api/generated/_cfg_totp/api.ts +120 -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 +25 -0
- package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesDestroy.ts +24 -0
- package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +25 -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 +29 -0
- 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 → _cfg_totp/schemas/TotpVerifyUser.ts} +17 -25
- 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 +5 -0
- package/src/_api/generated/_cfg_totp/types.gen.ts +5 -0
- package/src/_api/generated/client/client.gen.ts +280 -0
- package/src/_api/generated/client/index.ts +25 -0
- package/src/_api/generated/client/types.gen.ts +217 -0
- package/src/_api/generated/client/utils.gen.ts +318 -0
- package/src/_api/generated/client.gen.ts +16 -0
- package/src/_api/generated/core/auth.gen.ts +41 -0
- package/src/_api/generated/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/core/params.gen.ts +169 -0
- package/src/_api/generated/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/core/types.gen.ts +104 -0
- package/src/_api/generated/core/utils.gen.ts +140 -0
- package/src/_api/generated/helpers/errors.ts +70 -0
- package/src/_api/generated/helpers/index.ts +25 -0
- package/src/_api/generated/helpers/logger.ts +123 -0
- package/src/_api/generated/helpers/storage.ts +83 -0
- package/src/_api/generated/helpers/validation-events.ts +52 -0
- package/src/_api/generated/index.ts +28 -0
- package/src/_api/generated/sdk.gen.ts +1250 -0
- package/src/_api/generated/types.gen.ts +1294 -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 +3 -1
- package/src/auth/hooks/useGithubAuth.ts +13 -11
- package/src/auth/hooks/useTokenRefresh.ts +7 -4
- package/src/auth/hooks/useTwoFactor.ts +15 -8
- package/src/auth/hooks/useTwoFactorSetup.ts +9 -5
- package/src/auth/hooks/useTwoFactorStatus.ts +5 -3
- package/src/auth/middlewares/tokenRefresh.ts +7 -4
- package/src/clients.ts +14 -51
- package/src/index.ts +35 -60
- 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/index.ts +0 -338
- 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/index.ts +0 -316
- 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/index.ts +0 -345
- 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
package/src/_api/index.ts
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
export * from './generated
|
|
6
|
-
export { Schemas, Fetchers, Enums } from './generated/cfg_accounts';
|
|
7
|
-
export * as CfgAccountsTypes from './generated/cfg_accounts';
|
|
8
|
-
|
|
9
|
-
// cfg_centrifugo
|
|
10
|
-
export { getCentrifugoAuthTokenRetrieve } from './generated/cfg_centrifugo';
|
|
11
|
-
export * as CentrifugoHooks from './generated/cfg_centrifugo/_utils/hooks';
|
|
12
|
-
export * as CentrifugoFetchers from './generated/cfg_centrifugo/_utils/fetchers';
|
|
13
|
-
export * as CentrifugoTypes from './generated/cfg_centrifugo/_utils/schemas';
|
|
14
|
-
|
|
15
|
-
// cfg_totp
|
|
16
|
-
export * as TotpHooks from './generated/cfg_totp/_utils/hooks';
|
|
17
|
-
export * as TotpFetchers from './generated/cfg_totp/_utils/fetchers';
|
|
18
|
-
export * as TotpTypes from './generated/cfg_totp/_utils/schemas';
|
|
19
|
-
|
|
20
|
-
// API Classes
|
|
21
|
-
export { API as AccountsAPI } from './generated/cfg_accounts';
|
|
22
|
-
export { API as TotpAPI } from './generated/cfg_totp';
|
|
23
|
-
export { API as CentrifugoAPI } from './generated/cfg_centrifugo';
|
|
1
|
+
// Re-export the generated barrel directly. Per-group API singletons,
|
|
2
|
+
// API classes (AccountsAPI/TotpAPI/CentrifugoAPI), and shared utilities
|
|
3
|
+
// (LocalStorageAdapter / MemoryStorageAdapter / APIError / ...) all come
|
|
4
|
+
// from `_api/generated/index.ts`.
|
|
5
|
+
export * from './generated';
|
|
@@ -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/
|
|
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/helpers';
|
|
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';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { apiAccounts } from '../../clients';
|
|
6
|
+
import { UserProfile } from '../../_api/generated/sdk.gen';
|
|
6
7
|
import { useAuth } from '../context';
|
|
7
8
|
import { authLogger } from '../utils/logger';
|
|
8
9
|
|
|
@@ -60,7 +61,8 @@ export const useDeleteAccount = (): UseDeleteAccountReturn => {
|
|
|
60
61
|
try {
|
|
61
62
|
authLogger.info('Deleting account...');
|
|
62
63
|
|
|
63
|
-
const
|
|
64
|
+
const result = await UserProfile.cfgAccountsProfileDeleteCreate({ throwOnError: true });
|
|
65
|
+
const response = result.data;
|
|
64
66
|
|
|
65
67
|
if (!response.success) {
|
|
66
68
|
authLogger.error('Failed to delete account:', response.message);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { apiAccounts } from '../../clients';
|
|
6
|
+
import { OAuth } from '../../_api/generated/sdk.gen';
|
|
6
7
|
import { Analytics, AnalyticsCategory, AnalyticsEvent } from '../utils/analytics';
|
|
7
8
|
import { authLogger } from '../utils/logger';
|
|
8
9
|
import { useCfgRouter } from './useCfgRouter';
|
|
@@ -69,9 +70,13 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
69
70
|
|
|
70
71
|
// Call API to get authorization URL
|
|
71
72
|
// The API will auto-generate redirect_uri from config if not provided
|
|
72
|
-
const
|
|
73
|
-
|
|
73
|
+
const result = await OAuth.cfgAccountsOauthGithubAuthorizeCreate({
|
|
74
|
+
body: {
|
|
75
|
+
source_url: sourceUrl || (typeof window !== 'undefined' ? window.location.href : ''),
|
|
76
|
+
},
|
|
77
|
+
throwOnError: true,
|
|
74
78
|
});
|
|
79
|
+
const response = result.data;
|
|
75
80
|
|
|
76
81
|
if (!response.authorization_url) {
|
|
77
82
|
throw new Error('Failed to get authorization URL');
|
|
@@ -79,13 +84,11 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
79
84
|
|
|
80
85
|
authLogger.info('Redirecting to GitHub...', response.authorization_url);
|
|
81
86
|
|
|
82
|
-
// Store state in sessionStorage for verification on callback
|
|
83
87
|
if (typeof window !== 'undefined') {
|
|
84
88
|
sessionStorage.setItem('oauth_state', response.state);
|
|
85
89
|
sessionStorage.setItem('oauth_provider', 'github');
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
// Redirect to GitHub
|
|
89
92
|
window.location.href = response.authorization_url;
|
|
90
93
|
|
|
91
94
|
} catch (err) {
|
|
@@ -128,12 +131,11 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
128
131
|
sessionStorage.removeItem('oauth_provider');
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
code,
|
|
135
|
-
state,
|
|
134
|
+
const result = await OAuth.cfgAccountsOauthGithubCallbackCreate({
|
|
135
|
+
body: { code, state },
|
|
136
|
+
throwOnError: true,
|
|
136
137
|
});
|
|
138
|
+
const response = result.data;
|
|
137
139
|
|
|
138
140
|
// Check if 2FA is required
|
|
139
141
|
if (response.requires_2fa && response.session_id) {
|
|
@@ -156,8 +158,8 @@ export const useGithubAuth = (options: UseGithubAuthOptions = {}): UseGithubAuth
|
|
|
156
158
|
|
|
157
159
|
authLogger.info('GitHub OAuth successful, user:', response.user);
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
apiAccounts.
|
|
161
|
+
apiAccounts.setToken(response.access);
|
|
162
|
+
apiAccounts.setRefreshToken(response.refresh);
|
|
161
163
|
|
|
162
164
|
// Track successful OAuth
|
|
163
165
|
Analytics.event(AnalyticsEvent.AUTH_LOGIN_SUCCESS, {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { useCallback, useEffect, useRef } from 'react';
|
|
13
13
|
|
|
14
14
|
import { api as apiAccounts } from '../../';
|
|
15
|
+
import { Auth } from '../../_api/generated/sdk.gen';
|
|
15
16
|
import { authLogger } from '../utils/logger';
|
|
16
17
|
|
|
17
18
|
// Configuration
|
|
@@ -77,17 +78,19 @@ export function useTokenRefresh(options: UseTokenRefreshOptions = {}) {
|
|
|
77
78
|
|
|
78
79
|
try {
|
|
79
80
|
// Use generated API client with correct URL (/cfg/accounts/token/refresh/)
|
|
80
|
-
const result = await
|
|
81
|
-
refresh: refreshTokenValue,
|
|
81
|
+
const result = await Auth.cfgAccountsTokenRefreshCreate({
|
|
82
|
+
body: { refresh: refreshTokenValue },
|
|
83
|
+
throwOnError: true,
|
|
82
84
|
});
|
|
83
85
|
|
|
84
|
-
const newAccessToken = result.access;
|
|
86
|
+
const newAccessToken = result.data.access;
|
|
85
87
|
|
|
86
88
|
if (!newAccessToken) {
|
|
87
89
|
throw new Error('No access token in refresh response');
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
apiAccounts.setToken(newAccessToken
|
|
92
|
+
apiAccounts.setToken(newAccessToken);
|
|
93
|
+
apiAccounts.setRefreshToken(refreshTokenValue);
|
|
91
94
|
authLogger.info('Token refreshed successfully');
|
|
92
95
|
|
|
93
96
|
onRefresh?.(newAccessToken);
|
|
@@ -3,7 +3,8 @@
|
|
|
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/helpers';
|
|
7
|
+
import { TotpVerification } from '../../_api/generated/sdk.gen';
|
|
7
8
|
import { Analytics, AnalyticsCategory, AnalyticsEvent } from '../utils/analytics';
|
|
8
9
|
import { authLogger } from '../utils/logger';
|
|
9
10
|
import { useCfgRouter } from './useCfgRouter';
|
|
@@ -88,7 +89,8 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
88
89
|
remaining_backup_codes?: number;
|
|
89
90
|
}) => {
|
|
90
91
|
// Save tokens
|
|
91
|
-
apiAccounts.setToken(response.access_token
|
|
92
|
+
apiAccounts.setToken(response.access_token);
|
|
93
|
+
apiAccounts.setRefreshToken(response.refresh_token);
|
|
92
94
|
|
|
93
95
|
// Set warning if any
|
|
94
96
|
if (response.warning) {
|
|
@@ -146,10 +148,11 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
146
148
|
try {
|
|
147
149
|
authLogger.info('Verifying TOTP code...');
|
|
148
150
|
|
|
149
|
-
const
|
|
150
|
-
session_id: sessionId,
|
|
151
|
-
|
|
151
|
+
const result = await TotpVerification.cfgTotpVerifyCreate({
|
|
152
|
+
body: { session_id: sessionId, code },
|
|
153
|
+
throwOnError: true,
|
|
152
154
|
});
|
|
155
|
+
const response = result.data;
|
|
153
156
|
|
|
154
157
|
if (!response.access_token || !response.refresh_token) {
|
|
155
158
|
throw new Error('Invalid response from 2FA verification');
|
|
@@ -205,10 +208,14 @@ export const useTwoFactor = (options: UseTwoFactorOptions = {}): UseTwoFactorRet
|
|
|
205
208
|
try {
|
|
206
209
|
authLogger.info('Verifying backup code...');
|
|
207
210
|
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
const result = await TotpVerification.cfgTotpVerifyBackupCreate({
|
|
212
|
+
body: {
|
|
213
|
+
session_id: sessionId,
|
|
214
|
+
backup_code: backupCode.replace(/\s+/g, ''),
|
|
215
|
+
},
|
|
216
|
+
throwOnError: true,
|
|
211
217
|
});
|
|
218
|
+
const response = result.data;
|
|
212
219
|
|
|
213
220
|
if (!response.access_token || !response.refresh_token) {
|
|
214
221
|
throw new Error('Invalid response from backup code verification');
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { apiTotp } from '../../clients';
|
|
6
|
+
import { TotpSetup } from '../../_api/generated/sdk.gen';
|
|
6
7
|
import { authLogger } from '../utils/logger';
|
|
7
8
|
|
|
8
9
|
export interface TwoFactorSetupData {
|
|
@@ -115,9 +116,11 @@ export const useTwoFactorSetup = (options: UseTwoFactorSetupOptions = {}): UseTw
|
|
|
115
116
|
try {
|
|
116
117
|
authLogger.info('Starting 2FA setup...');
|
|
117
118
|
|
|
118
|
-
const
|
|
119
|
-
device_name: deviceName,
|
|
119
|
+
const result = await TotpSetup.cfgTotpSetupCreate({
|
|
120
|
+
body: { device_name: deviceName },
|
|
121
|
+
throwOnError: true,
|
|
120
122
|
});
|
|
123
|
+
const response = result.data;
|
|
121
124
|
|
|
122
125
|
const data: TwoFactorSetupData = {
|
|
123
126
|
deviceId: response.device_id,
|
|
@@ -169,10 +172,11 @@ export const useTwoFactorSetup = (options: UseTwoFactorSetupOptions = {}): UseTw
|
|
|
169
172
|
try {
|
|
170
173
|
authLogger.info('Confirming 2FA setup...');
|
|
171
174
|
|
|
172
|
-
const
|
|
173
|
-
device_id: setupData.deviceId,
|
|
174
|
-
|
|
175
|
+
const result = await TotpSetup.cfgTotpSetupConfirmCreate({
|
|
176
|
+
body: { device_id: setupData.deviceId, code },
|
|
177
|
+
throwOnError: true,
|
|
175
178
|
});
|
|
179
|
+
const response = result.data;
|
|
176
180
|
|
|
177
181
|
const codes = response.backup_codes;
|
|
178
182
|
setBackupCodes(codes);
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { useCallback, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { apiTotp } from '../../clients';
|
|
6
|
-
import { APIError } from '../../_api/generated/
|
|
6
|
+
import { APIError } from '../../_api/generated/helpers';
|
|
7
|
+
import { TotpManagement } from '../../_api/generated/sdk.gen';
|
|
7
8
|
import { authLogger } from '../utils/logger';
|
|
8
9
|
|
|
9
10
|
export interface TwoFactorDevice {
|
|
@@ -82,7 +83,8 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
|
|
|
82
83
|
authLogger.info('Fetching 2FA status...');
|
|
83
84
|
|
|
84
85
|
// API returns { devices: [...], has_2fa_enabled: bool }
|
|
85
|
-
const
|
|
86
|
+
const result = await TotpManagement.cfgTotpDevicesRetrieve({ throwOnError: true });
|
|
87
|
+
const response = result.data;
|
|
86
88
|
|
|
87
89
|
const mappedDevices: TwoFactorDevice[] = response.devices.map((device) => ({
|
|
88
90
|
id: device.id,
|
|
@@ -121,7 +123,7 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
|
|
|
121
123
|
try {
|
|
122
124
|
authLogger.info('Disabling 2FA...');
|
|
123
125
|
|
|
124
|
-
await
|
|
126
|
+
await TotpManagement.cfgTotpDisableCreate({ body: { code }, throwOnError: true });
|
|
125
127
|
|
|
126
128
|
setHas2FAEnabled(false);
|
|
127
129
|
setDevices([]);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { api as apiAccounts } from '../../';
|
|
9
|
+
import { Auth } from '../../_api/generated/sdk.gen';
|
|
9
10
|
import { authLogger } from '../utils/logger';
|
|
10
11
|
|
|
11
12
|
// Refresh state management
|
|
@@ -51,11 +52,12 @@ export async function refreshAccessToken(): Promise<string | null> {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// Use generated API client with correct URL (/cfg/accounts/token/refresh/)
|
|
54
|
-
const result = await
|
|
55
|
-
refresh: refreshToken,
|
|
55
|
+
const result = await Auth.cfgAccountsTokenRefreshCreate({
|
|
56
|
+
body: { refresh: refreshToken },
|
|
57
|
+
throwOnError: true,
|
|
56
58
|
});
|
|
57
59
|
|
|
58
|
-
const newAccessToken = result.access;
|
|
60
|
+
const newAccessToken = result.data.access;
|
|
59
61
|
|
|
60
62
|
if (!newAccessToken) {
|
|
61
63
|
authLogger.error('Token refresh response missing access token');
|
|
@@ -64,7 +66,8 @@ export async function refreshAccessToken(): Promise<string | null> {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
// Update tokens in storage
|
|
67
|
-
apiAccounts.setToken(newAccessToken
|
|
69
|
+
apiAccounts.setToken(newAccessToken);
|
|
70
|
+
apiAccounts.setRefreshToken(refreshToken);
|
|
68
71
|
authLogger.info('Token refreshed successfully');
|
|
69
72
|
|
|
70
73
|
onTokenRefreshed(newAccessToken);
|