@djangocfg/api 2.1.545 → 2.1.547
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.cjs +331 -73
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +90 -1
- package/dist/auth.d.ts +90 -1
- package/dist/auth.mjs +331 -73
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +18 -0
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +96 -0
- package/dist/clients.d.ts +96 -0
- package/dist/clients.mjs +18 -0
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +171 -3
- package/dist/index.d.ts +171 -3
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/_cfg_accounts/hooks/index.ts +1 -0
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenCreate.ts +64 -0
- package/src/_api/generated/_cfg_accounts/openapi.json +157 -0
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginError.ts +13 -0
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginRequest.ts +13 -0
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginResponse.ts +18 -0
- package/src/_api/generated/_cfg_accounts/schemas/index.ts +3 -0
- package/src/_api/generated/openapi.json +157 -0
- package/src/_api/generated/sdk.gen.ts +20 -1
- package/src/_api/generated/types.gen.ts +149 -0
- package/src/auth/__tests__/passwordLogin.test.tsx +239 -0
- package/src/auth/context/AccountsContext.tsx +32 -7
- package/src/auth/context/AuthContext.tsx +104 -1
- package/src/auth/context/types.ts +10 -1
- package/src/auth/hooks/useAuthForm.ts +84 -0
- package/src/auth/hooks/useAuthFormState.ts +3 -0
- package/src/auth/types/form.ts +41 -1
- package/src/auth/types/index.ts +2 -0
- package/src/auth/utils/analytics.ts +1 -0
package/dist/auth.cjs
CHANGED
|
@@ -1044,6 +1044,7 @@ var formatCountdown = /* @__PURE__ */ __name((s) => {
|
|
|
1044
1044
|
var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
1045
1045
|
const [identifier, setIdentifier] = (0, import_react4.useState)(initialIdentifier);
|
|
1046
1046
|
const [otp, setOtp] = (0, import_react4.useState)("");
|
|
1047
|
+
const [password, setPassword] = (0, import_react4.useState)("");
|
|
1047
1048
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
1048
1049
|
const [acceptedTerms, setAcceptedTerms] = (0, import_react4.useState)(true);
|
|
1049
1050
|
const [marketingConsent, setMarketingConsent] = (0, import_react4.useState)(null);
|
|
@@ -1079,6 +1080,7 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1079
1080
|
// State
|
|
1080
1081
|
identifier,
|
|
1081
1082
|
otp,
|
|
1083
|
+
password,
|
|
1082
1084
|
isLoading,
|
|
1083
1085
|
acceptedTerms,
|
|
1084
1086
|
marketingConsent,
|
|
@@ -1096,6 +1098,7 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1096
1098
|
// Handlers
|
|
1097
1099
|
setIdentifier,
|
|
1098
1100
|
setOtp,
|
|
1101
|
+
setPassword,
|
|
1099
1102
|
setAcceptedTerms,
|
|
1100
1103
|
setMarketingConsent,
|
|
1101
1104
|
setRememberMe,
|
|
@@ -2310,6 +2313,24 @@ var CfgAccountsAuth = class {
|
|
|
2310
2313
|
static {
|
|
2311
2314
|
__name(this, "CfgAccountsAuth");
|
|
2312
2315
|
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Obtain a JWT pair with email + password.
|
|
2318
|
+
*
|
|
2319
|
+
* Returns the same envelope as OTP verify: either ``requires_2fa=True`` with
|
|
2320
|
+
* a session id, or the token pair plus the user object. Failures are uniform
|
|
2321
|
+
* (401 ``invalid_credentials``) whether the email is unknown, the password is
|
|
2322
|
+
* wrong, or the account is inactive/soft-deleted — no enumeration.
|
|
2323
|
+
*/
|
|
2324
|
+
static cfgAccountsTokenCreate(options) {
|
|
2325
|
+
return (options.client ?? client).post({
|
|
2326
|
+
url: "/cfg/accounts/token/",
|
|
2327
|
+
...options,
|
|
2328
|
+
headers: {
|
|
2329
|
+
"Content-Type": "application/json",
|
|
2330
|
+
...options.headers
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2313
2334
|
/**
|
|
2314
2335
|
* Revoke a refresh token (logout).
|
|
2315
2336
|
*
|
|
@@ -2498,6 +2519,7 @@ var AnalyticsEvent = /* @__PURE__ */ ((AnalyticsEvent2) => {
|
|
|
2498
2519
|
AnalyticsEvent2["AUTH_OTP_REQUEST"] = "auth_otp_request";
|
|
2499
2520
|
AnalyticsEvent2["AUTH_LOGIN_SUCCESS"] = "auth_login_success";
|
|
2500
2521
|
AnalyticsEvent2["AUTH_OTP_VERIFY_FAIL"] = "auth_otp_verify_fail";
|
|
2522
|
+
AnalyticsEvent2["AUTH_PASSWORD_LOGIN_FAIL"] = "auth_password_login_fail";
|
|
2501
2523
|
AnalyticsEvent2["AUTH_SESSION_EXPIRED"] = "auth_session_expired";
|
|
2502
2524
|
AnalyticsEvent2["AUTH_TOKEN_REFRESH"] = "auth_token_refresh";
|
|
2503
2525
|
AnalyticsEvent2["AUTH_TOKEN_REFRESH_FAIL"] = "auth_token_refresh_fail";
|
|
@@ -2937,12 +2959,14 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
2937
2959
|
const {
|
|
2938
2960
|
requestOTP,
|
|
2939
2961
|
verifyOTP,
|
|
2962
|
+
login,
|
|
2940
2963
|
getSavedEmail,
|
|
2941
2964
|
saveEmail
|
|
2942
2965
|
} = useAuth();
|
|
2943
2966
|
const {
|
|
2944
2967
|
identifier,
|
|
2945
2968
|
otp,
|
|
2969
|
+
password,
|
|
2946
2970
|
acceptedTerms,
|
|
2947
2971
|
marketingConsent,
|
|
2948
2972
|
rememberMe,
|
|
@@ -3094,6 +3118,78 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
3094
3118
|
e.preventDefault();
|
|
3095
3119
|
await submitOTP(identifier, otp);
|
|
3096
3120
|
}, [identifier, otp, submitOTP]);
|
|
3121
|
+
const submitPassword = (0, import_react9.useCallback)(async (submitIdentifier, submitPassword_) => {
|
|
3122
|
+
if (!submitIdentifier || !validateIdentifier2(submitIdentifier)) {
|
|
3123
|
+
const msg = "Please enter a valid email address";
|
|
3124
|
+
setError(msg);
|
|
3125
|
+
onError?.(msg);
|
|
3126
|
+
return false;
|
|
3127
|
+
}
|
|
3128
|
+
if (!submitPassword_) {
|
|
3129
|
+
const msg = "Please enter your password";
|
|
3130
|
+
setError(msg);
|
|
3131
|
+
onError?.(msg);
|
|
3132
|
+
return false;
|
|
3133
|
+
}
|
|
3134
|
+
setIsLoading(true);
|
|
3135
|
+
clearError();
|
|
3136
|
+
try {
|
|
3137
|
+
const result = await login(submitIdentifier, submitPassword_, {
|
|
3138
|
+
redirectUrl,
|
|
3139
|
+
skipRedirect: true,
|
|
3140
|
+
rememberMe
|
|
3141
|
+
});
|
|
3142
|
+
if (result.requires_2fa && result.session_id) {
|
|
3143
|
+
authLogger.info("2FA required after password login");
|
|
3144
|
+
setTwoFactorSessionId(result.session_id);
|
|
3145
|
+
setShouldPrompt2FA(result.should_prompt_2fa || false);
|
|
3146
|
+
setStep("2fa");
|
|
3147
|
+
saveIdentifierToStorage(submitIdentifier);
|
|
3148
|
+
return true;
|
|
3149
|
+
}
|
|
3150
|
+
if (result.success) {
|
|
3151
|
+
saveIdentifierToStorage(submitIdentifier);
|
|
3152
|
+
authLogger.info("Password login successful, showing success screen");
|
|
3153
|
+
setStep("success");
|
|
3154
|
+
onOTPSuccess?.();
|
|
3155
|
+
return true;
|
|
3156
|
+
}
|
|
3157
|
+
if (result.retryAfter) {
|
|
3158
|
+
startRateLimitCountdown(result.retryAfter);
|
|
3159
|
+
clearError();
|
|
3160
|
+
} else {
|
|
3161
|
+
setError(result.message);
|
|
3162
|
+
onError?.(result.message);
|
|
3163
|
+
}
|
|
3164
|
+
return false;
|
|
3165
|
+
} catch {
|
|
3166
|
+
const msg = "An unexpected error occurred";
|
|
3167
|
+
setError(msg);
|
|
3168
|
+
onError?.(msg);
|
|
3169
|
+
return false;
|
|
3170
|
+
} finally {
|
|
3171
|
+
setIsLoading(false);
|
|
3172
|
+
}
|
|
3173
|
+
}, [
|
|
3174
|
+
login,
|
|
3175
|
+
validateIdentifier2,
|
|
3176
|
+
saveIdentifierToStorage,
|
|
3177
|
+
setError,
|
|
3178
|
+
setIsLoading,
|
|
3179
|
+
clearError,
|
|
3180
|
+
startRateLimitCountdown,
|
|
3181
|
+
onOTPSuccess,
|
|
3182
|
+
onError,
|
|
3183
|
+
redirectUrl,
|
|
3184
|
+
rememberMe,
|
|
3185
|
+
setTwoFactorSessionId,
|
|
3186
|
+
setShouldPrompt2FA,
|
|
3187
|
+
setStep
|
|
3188
|
+
]);
|
|
3189
|
+
const handlePasswordSubmit = (0, import_react9.useCallback)(async (e) => {
|
|
3190
|
+
e.preventDefault();
|
|
3191
|
+
await submitPassword(identifier, password);
|
|
3192
|
+
}, [identifier, password, submitPassword]);
|
|
3097
3193
|
const handleResendOTP = (0, import_react9.useCallback)(async () => {
|
|
3098
3194
|
setIsLoading(true);
|
|
3099
3195
|
clearError();
|
|
@@ -3187,6 +3283,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
3187
3283
|
// Submit handlers
|
|
3188
3284
|
handleIdentifierSubmit,
|
|
3189
3285
|
handleOTPSubmit,
|
|
3286
|
+
handlePasswordSubmit,
|
|
3190
3287
|
handleResendOTP,
|
|
3191
3288
|
handleBackToIdentifier,
|
|
3192
3289
|
forceOTPStep,
|
|
@@ -4290,119 +4387,197 @@ __name(useCfgAccountsProfileUpdateUpdate, "useCfgAccountsProfileUpdateUpdate");
|
|
|
4290
4387
|
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenBlacklistCreate.ts
|
|
4291
4388
|
var import_mutation15 = __toESM(require("swr/mutation"), 1);
|
|
4292
4389
|
|
|
4293
|
-
// src/_api/generated/_cfg_accounts/hooks/
|
|
4390
|
+
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenCreate.ts
|
|
4294
4391
|
var import_mutation16 = __toESM(require("swr/mutation"), 1);
|
|
4295
4392
|
|
|
4296
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4393
|
+
// src/_api/generated/_cfg_accounts/schemas/PasswordLoginResponse.ts
|
|
4297
4394
|
var import_zod20 = require("zod");
|
|
4298
|
-
var
|
|
4299
|
-
|
|
4300
|
-
|
|
4395
|
+
var PasswordLoginResponseSchema = import_zod20.z.object({
|
|
4396
|
+
requires_2fa: import_zod20.z.boolean().default(false).optional(),
|
|
4397
|
+
session_id: import_zod20.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
|
|
4398
|
+
refresh: import_zod20.z.string().nullable().optional(),
|
|
4399
|
+
access: import_zod20.z.string().nullable().optional(),
|
|
4400
|
+
user: UserSchema.nullable().optional(),
|
|
4401
|
+
should_prompt_2fa: import_zod20.z.boolean().optional(),
|
|
4402
|
+
persistent_session: import_zod20.z.boolean().optional()
|
|
4301
4403
|
});
|
|
4302
4404
|
|
|
4303
|
-
// src/_api/generated/_cfg_accounts/
|
|
4405
|
+
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenCreate.ts
|
|
4406
|
+
function useCfgAccountsTokenCreate(config) {
|
|
4407
|
+
return (0, import_mutation16.default)(
|
|
4408
|
+
["cfg_accounts_token_create"],
|
|
4409
|
+
async (_key, { arg }) => {
|
|
4410
|
+
const res = await CfgAccountsAuth.cfgAccountsTokenCreate({ ...arg, throwOnError: true });
|
|
4411
|
+
const data = res.data;
|
|
4412
|
+
const parsed = PasswordLoginResponseSchema.safeParse(data);
|
|
4413
|
+
if (!parsed.success) {
|
|
4414
|
+
console.warn(
|
|
4415
|
+
"[zod] response did not match schema",
|
|
4416
|
+
{
|
|
4417
|
+
operation: "cfg_accounts_token_create",
|
|
4418
|
+
method: "POST",
|
|
4419
|
+
path: "/cfg/accounts/token/",
|
|
4420
|
+
issues: parsed.error.issues,
|
|
4421
|
+
data
|
|
4422
|
+
}
|
|
4423
|
+
);
|
|
4424
|
+
if (typeof window !== "undefined") {
|
|
4425
|
+
try {
|
|
4426
|
+
window.dispatchEvent(
|
|
4427
|
+
new CustomEvent("zod-validation-error", {
|
|
4428
|
+
detail: {
|
|
4429
|
+
operation: "cfg_accounts_token_create",
|
|
4430
|
+
method: "POST",
|
|
4431
|
+
path: "/cfg/accounts/token/",
|
|
4432
|
+
issues: parsed.error.issues,
|
|
4433
|
+
data,
|
|
4434
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
4435
|
+
},
|
|
4436
|
+
bubbles: true,
|
|
4437
|
+
cancelable: false
|
|
4438
|
+
})
|
|
4439
|
+
);
|
|
4440
|
+
} catch {
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
return data;
|
|
4444
|
+
}
|
|
4445
|
+
return parsed.data;
|
|
4446
|
+
},
|
|
4447
|
+
config
|
|
4448
|
+
);
|
|
4449
|
+
}
|
|
4450
|
+
__name(useCfgAccountsTokenCreate, "useCfgAccountsTokenCreate");
|
|
4451
|
+
|
|
4452
|
+
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenRefreshCreate.ts
|
|
4453
|
+
var import_mutation17 = __toESM(require("swr/mutation"), 1);
|
|
4454
|
+
|
|
4455
|
+
// src/_api/generated/_cfg_accounts/schemas/TokenRefresh.ts
|
|
4304
4456
|
var import_zod21 = require("zod");
|
|
4305
|
-
var
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
created_at: import_zod21.z.string().datetime({ offset: true })
|
|
4457
|
+
var TokenRefreshSchema = import_zod21.z.object({
|
|
4458
|
+
access: import_zod21.z.string(),
|
|
4459
|
+
refresh: import_zod21.z.string()
|
|
4309
4460
|
});
|
|
4310
4461
|
|
|
4311
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4462
|
+
// src/_api/generated/_cfg_accounts/schemas/APIKeyRequest.ts
|
|
4312
4463
|
var import_zod22 = require("zod");
|
|
4313
|
-
var
|
|
4314
|
-
key: import_zod22.z.string().min(1)
|
|
4464
|
+
var APIKeyRequestSchema = import_zod22.z.object({
|
|
4465
|
+
key: import_zod22.z.string().min(1),
|
|
4466
|
+
reissued_at: import_zod22.z.string().datetime({ offset: true }).nullable(),
|
|
4467
|
+
created_at: import_zod22.z.string().datetime({ offset: true })
|
|
4315
4468
|
});
|
|
4316
4469
|
|
|
4317
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4470
|
+
// src/_api/generated/_cfg_accounts/schemas/APIKeyTestRequest.ts
|
|
4318
4471
|
var import_zod23 = require("zod");
|
|
4319
|
-
var
|
|
4320
|
-
|
|
4321
|
-
last_name: import_zod23.z.string().max(50).optional(),
|
|
4322
|
-
company: import_zod23.z.string().max(100).optional(),
|
|
4323
|
-
phone: import_zod23.z.string().max(20).optional(),
|
|
4324
|
-
position: import_zod23.z.string().max(100).optional(),
|
|
4325
|
-
language: import_zod23.z.string().max(10).optional(),
|
|
4326
|
-
timezone: import_zod23.z.string().max(64).optional()
|
|
4472
|
+
var APIKeyTestRequestSchema = import_zod23.z.object({
|
|
4473
|
+
key: import_zod23.z.string().min(1)
|
|
4327
4474
|
});
|
|
4328
4475
|
|
|
4329
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4476
|
+
// src/_api/generated/_cfg_accounts/schemas/CfgUserUpdateRequest.ts
|
|
4330
4477
|
var import_zod24 = require("zod");
|
|
4331
|
-
var
|
|
4332
|
-
|
|
4333
|
-
|
|
4478
|
+
var CfgUserUpdateRequestSchema = import_zod24.z.object({
|
|
4479
|
+
first_name: import_zod24.z.string().max(50).optional(),
|
|
4480
|
+
last_name: import_zod24.z.string().max(50).optional(),
|
|
4481
|
+
company: import_zod24.z.string().max(100).optional(),
|
|
4482
|
+
phone: import_zod24.z.string().max(20).optional(),
|
|
4483
|
+
position: import_zod24.z.string().max(100).optional(),
|
|
4484
|
+
language: import_zod24.z.string().max(10).optional(),
|
|
4485
|
+
timezone: import_zod24.z.string().max(64).optional()
|
|
4334
4486
|
});
|
|
4335
4487
|
|
|
4336
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4488
|
+
// src/_api/generated/_cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts
|
|
4337
4489
|
var import_zod25 = require("zod");
|
|
4338
|
-
var
|
|
4339
|
-
code: import_zod25.z.string().min(10).max(500),
|
|
4340
|
-
state: import_zod25.z.string().min(20).max(100),
|
|
4490
|
+
var OAuthAuthorizeRequestRequestSchema = import_zod25.z.object({
|
|
4341
4491
|
redirect_uri: import_zod25.z.string().optional(),
|
|
4342
|
-
|
|
4492
|
+
source_url: import_zod25.z.string().optional()
|
|
4343
4493
|
});
|
|
4344
4494
|
|
|
4345
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4495
|
+
// src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts
|
|
4346
4496
|
var import_zod26 = require("zod");
|
|
4347
|
-
var
|
|
4348
|
-
|
|
4497
|
+
var OAuthCallbackRequestRequestSchema = import_zod26.z.object({
|
|
4498
|
+
code: import_zod26.z.string().min(10).max(500),
|
|
4499
|
+
state: import_zod26.z.string().min(20).max(100),
|
|
4500
|
+
redirect_uri: import_zod26.z.string().optional(),
|
|
4501
|
+
remember_me: import_zod26.z.boolean().default(false).optional()
|
|
4349
4502
|
});
|
|
4350
4503
|
|
|
4351
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4504
|
+
// src/_api/generated/_cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts
|
|
4352
4505
|
var import_zod27 = require("zod");
|
|
4353
|
-
var
|
|
4354
|
-
|
|
4355
|
-
error_description: import_zod27.z.string().optional()
|
|
4506
|
+
var OAuthDisconnectRequestRequestSchema = import_zod27.z.object({
|
|
4507
|
+
provider: OAuthProviderEnumSchema
|
|
4356
4508
|
});
|
|
4357
4509
|
|
|
4358
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4510
|
+
// src/_api/generated/_cfg_accounts/schemas/OAuthError.ts
|
|
4359
4511
|
var import_zod28 = require("zod");
|
|
4360
|
-
var
|
|
4512
|
+
var OAuthErrorSchema = import_zod28.z.object({
|
|
4361
4513
|
error: import_zod28.z.string(),
|
|
4362
|
-
|
|
4363
|
-
retry_after: import_zod28.z.number().int().nullable().optional()
|
|
4514
|
+
error_description: import_zod28.z.string().optional()
|
|
4364
4515
|
});
|
|
4365
4516
|
|
|
4366
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4517
|
+
// src/_api/generated/_cfg_accounts/schemas/OTPErrorResponse.ts
|
|
4367
4518
|
var import_zod29 = require("zod");
|
|
4368
|
-
var
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
consent_disclosure_version: import_zod29.z.string().max(64).optional()
|
|
4519
|
+
var OTPErrorResponseSchema = import_zod29.z.object({
|
|
4520
|
+
error: import_zod29.z.string(),
|
|
4521
|
+
error_code: import_zod29.z.string().nullable().optional(),
|
|
4522
|
+
retry_after: import_zod29.z.number().int().nullable().optional()
|
|
4373
4523
|
});
|
|
4374
4524
|
|
|
4375
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4525
|
+
// src/_api/generated/_cfg_accounts/schemas/OTPRequestRequest.ts
|
|
4376
4526
|
var import_zod30 = require("zod");
|
|
4377
|
-
var
|
|
4527
|
+
var OTPRequestRequestSchema = import_zod30.z.object({
|
|
4378
4528
|
identifier: import_zod30.z.string().min(1),
|
|
4379
|
-
otp: import_zod30.z.string().min(4).max(4),
|
|
4380
4529
|
source_url: import_zod30.z.string().optional(),
|
|
4381
|
-
|
|
4530
|
+
marketing_consent: import_zod30.z.boolean().nullable().optional(),
|
|
4531
|
+
consent_disclosure_version: import_zod30.z.string().max(64).optional()
|
|
4382
4532
|
});
|
|
4383
4533
|
|
|
4384
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4534
|
+
// src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts
|
|
4385
4535
|
var import_zod31 = require("zod");
|
|
4386
|
-
var
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
position: import_zod31.z.string().max(100).optional(),
|
|
4392
|
-
language: import_zod31.z.string().max(10).optional(),
|
|
4393
|
-
timezone: import_zod31.z.string().max(64).optional()
|
|
4536
|
+
var OTPVerifyRequestSchema = import_zod31.z.object({
|
|
4537
|
+
identifier: import_zod31.z.string().min(1),
|
|
4538
|
+
otp: import_zod31.z.string().min(4).max(4),
|
|
4539
|
+
source_url: import_zod31.z.string().optional(),
|
|
4540
|
+
remember_me: import_zod31.z.boolean().default(false).optional()
|
|
4394
4541
|
});
|
|
4395
4542
|
|
|
4396
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4543
|
+
// src/_api/generated/_cfg_accounts/schemas/PasswordLoginError.ts
|
|
4397
4544
|
var import_zod32 = require("zod");
|
|
4398
|
-
var
|
|
4399
|
-
|
|
4545
|
+
var PasswordLoginErrorSchema = import_zod32.z.object({
|
|
4546
|
+
error: import_zod32.z.string(),
|
|
4547
|
+
error_code: import_zod32.z.string(),
|
|
4548
|
+
retry_after: import_zod32.z.number().int().nullable().optional()
|
|
4400
4549
|
});
|
|
4401
4550
|
|
|
4402
|
-
// src/_api/generated/_cfg_accounts/schemas/
|
|
4551
|
+
// src/_api/generated/_cfg_accounts/schemas/PasswordLoginRequest.ts
|
|
4403
4552
|
var import_zod33 = require("zod");
|
|
4404
|
-
var
|
|
4405
|
-
|
|
4553
|
+
var PasswordLoginRequestSchema = import_zod33.z.object({
|
|
4554
|
+
remember_me: import_zod33.z.boolean().default(false).optional(),
|
|
4555
|
+
email: import_zod33.z.email(),
|
|
4556
|
+
password: import_zod33.z.string()
|
|
4557
|
+
});
|
|
4558
|
+
|
|
4559
|
+
// src/_api/generated/_cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts
|
|
4560
|
+
var import_zod34 = require("zod");
|
|
4561
|
+
var PatchedCfgUserUpdateRequestSchema = import_zod34.z.object({
|
|
4562
|
+
first_name: import_zod34.z.string().max(50).optional(),
|
|
4563
|
+
last_name: import_zod34.z.string().max(50).optional(),
|
|
4564
|
+
company: import_zod34.z.string().max(100).optional(),
|
|
4565
|
+
phone: import_zod34.z.string().max(20).optional(),
|
|
4566
|
+
position: import_zod34.z.string().max(100).optional(),
|
|
4567
|
+
language: import_zod34.z.string().max(10).optional(),
|
|
4568
|
+
timezone: import_zod34.z.string().max(64).optional()
|
|
4569
|
+
});
|
|
4570
|
+
|
|
4571
|
+
// src/_api/generated/_cfg_accounts/schemas/TokenBlacklistRequest.ts
|
|
4572
|
+
var import_zod35 = require("zod");
|
|
4573
|
+
var TokenBlacklistRequestSchema = import_zod35.z.object({
|
|
4574
|
+
refresh: import_zod35.z.string().min(1)
|
|
4575
|
+
});
|
|
4576
|
+
|
|
4577
|
+
// src/_api/generated/_cfg_accounts/schemas/TokenRefreshRequest.ts
|
|
4578
|
+
var import_zod36 = require("zod");
|
|
4579
|
+
var TokenRefreshRequestSchema = import_zod36.z.object({
|
|
4580
|
+
refresh: import_zod36.z.string().min(1)
|
|
4406
4581
|
});
|
|
4407
4582
|
|
|
4408
4583
|
// src/auth/context/AccountsContext.tsx
|
|
@@ -4439,6 +4614,7 @@ function AccountsProvider({ children }) {
|
|
|
4439
4614
|
const { trigger: triggerAvatar } = useCfgAccountsProfileAvatarCreate();
|
|
4440
4615
|
const { trigger: triggerOtpRequest } = useCfgAccountsOtpRequestCreate();
|
|
4441
4616
|
const { trigger: triggerOtpVerify } = useCfgAccountsOtpVerifyCreate();
|
|
4617
|
+
const { trigger: triggerPasswordLogin } = useCfgAccountsTokenCreate();
|
|
4442
4618
|
const refreshProfile = (0, import_react15.useCallback)(async (options) => {
|
|
4443
4619
|
const { callerId, force } = options || {};
|
|
4444
4620
|
if (!hasApiOrigin()) {
|
|
@@ -4488,22 +4664,30 @@ function AccountsProvider({ children }) {
|
|
|
4488
4664
|
const result = await triggerOtpRequest({ body: data });
|
|
4489
4665
|
return result;
|
|
4490
4666
|
}, [triggerOtpRequest]);
|
|
4491
|
-
const
|
|
4492
|
-
const result = await triggerOtpVerify({ body: data });
|
|
4667
|
+
const settleLoginEnvelope = (0, import_react15.useCallback)(async (result, callerId) => {
|
|
4493
4668
|
if (result.requires_2fa && result.session_id) {
|
|
4494
4669
|
authLogger.info("2FA required, session:", result.session_id);
|
|
4495
|
-
return
|
|
4670
|
+
return;
|
|
4496
4671
|
}
|
|
4497
4672
|
if (result.access && result.refresh) {
|
|
4498
4673
|
auth.setSession({ access: result.access, refresh: result.refresh });
|
|
4499
4674
|
try {
|
|
4500
|
-
await refreshProfile({ callerId
|
|
4675
|
+
await refreshProfile({ callerId, force: true });
|
|
4501
4676
|
} catch (profileError2) {
|
|
4502
|
-
authLogger.warn(
|
|
4677
|
+
authLogger.warn(`Profile refresh failed after ${callerId} (tokens are saved):`, profileError2);
|
|
4503
4678
|
}
|
|
4504
4679
|
}
|
|
4680
|
+
}, [refreshProfile]);
|
|
4681
|
+
const verifyOTP = (0, import_react15.useCallback)(async (data) => {
|
|
4682
|
+
const result = await triggerOtpVerify({ body: data });
|
|
4683
|
+
await settleLoginEnvelope(result, "verifyOTP");
|
|
4684
|
+
return result;
|
|
4685
|
+
}, [triggerOtpVerify, settleLoginEnvelope]);
|
|
4686
|
+
const loginWithPassword = (0, import_react15.useCallback)(async (data) => {
|
|
4687
|
+
const result = await triggerPasswordLogin({ body: data });
|
|
4688
|
+
await settleLoginEnvelope(result, "loginWithPassword");
|
|
4505
4689
|
return result;
|
|
4506
|
-
}, [
|
|
4690
|
+
}, [triggerPasswordLogin, settleLoginEnvelope]);
|
|
4507
4691
|
const logout = (0, import_react15.useCallback)(() => {
|
|
4508
4692
|
const refresh = auth.getRefreshToken();
|
|
4509
4693
|
if (refresh) {
|
|
@@ -4526,6 +4710,7 @@ function AccountsProvider({ children }) {
|
|
|
4526
4710
|
refreshProfile,
|
|
4527
4711
|
requestOTP,
|
|
4528
4712
|
verifyOTP,
|
|
4713
|
+
loginWithPassword,
|
|
4529
4714
|
logout
|
|
4530
4715
|
}), [
|
|
4531
4716
|
profile,
|
|
@@ -4537,6 +4722,7 @@ function AccountsProvider({ children }) {
|
|
|
4537
4722
|
refreshProfile,
|
|
4538
4723
|
requestOTP,
|
|
4539
4724
|
verifyOTP,
|
|
4725
|
+
loginWithPassword,
|
|
4540
4726
|
logout
|
|
4541
4727
|
]);
|
|
4542
4728
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccountsContext.Provider, { value, children });
|
|
@@ -4773,6 +4959,72 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4773
4959
|
},
|
|
4774
4960
|
[setStoredEmail, redirectManager, router]
|
|
4775
4961
|
);
|
|
4962
|
+
const login = (0, import_react16.useCallback)(
|
|
4963
|
+
async (email, password, options) => {
|
|
4964
|
+
const { redirectUrl, skipRedirect, rememberMe = false } = options || {};
|
|
4965
|
+
try {
|
|
4966
|
+
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
4967
|
+
const result = await accountsRef.current.loginWithPassword({
|
|
4968
|
+
email,
|
|
4969
|
+
password,
|
|
4970
|
+
remember_me: rememberMe
|
|
4971
|
+
});
|
|
4972
|
+
if (result.requires_2fa && result.session_id) {
|
|
4973
|
+
authLogger.info("2FA required, session:", result.session_id);
|
|
4974
|
+
return {
|
|
4975
|
+
success: true,
|
|
4976
|
+
message: "Password verified, 2FA required",
|
|
4977
|
+
requires_2fa: true,
|
|
4978
|
+
session_id: result.session_id,
|
|
4979
|
+
should_prompt_2fa: result.should_prompt_2fa
|
|
4980
|
+
};
|
|
4981
|
+
}
|
|
4982
|
+
if (!result.access || !result.refresh) {
|
|
4983
|
+
authLogger.error("Password login returned invalid response:", result);
|
|
4984
|
+
return { success: false, message: "Invalid login response" };
|
|
4985
|
+
}
|
|
4986
|
+
setStoredEmail(email);
|
|
4987
|
+
Analytics.event("auth_login_success" /* AUTH_LOGIN_SUCCESS */, {
|
|
4988
|
+
category: "auth" /* AUTH */,
|
|
4989
|
+
label: "password"
|
|
4990
|
+
});
|
|
4991
|
+
if (result.user?.id) {
|
|
4992
|
+
Analytics.setUser(String(result.user.id));
|
|
4993
|
+
}
|
|
4994
|
+
if (!skipRedirect) {
|
|
4995
|
+
const saved = redirectManager.hasRedirect() ? redirectManager.getRedirect() : null;
|
|
4996
|
+
if (saved) redirectManager.clearRedirect();
|
|
4997
|
+
const finalRedirectUrl = saved || redirectUrl || routesRef.current.defaultCallback;
|
|
4998
|
+
authLogger.info("Redirecting after auth to:", finalRedirectUrl);
|
|
4999
|
+
router.hardPush(finalRedirectUrl);
|
|
5000
|
+
}
|
|
5001
|
+
return {
|
|
5002
|
+
success: true,
|
|
5003
|
+
message: "Login successful",
|
|
5004
|
+
user: result.user,
|
|
5005
|
+
should_prompt_2fa: result.should_prompt_2fa
|
|
5006
|
+
};
|
|
5007
|
+
} catch (error) {
|
|
5008
|
+
authLogger.error("Password login error:", error);
|
|
5009
|
+
Analytics.event("auth_password_login_fail" /* AUTH_PASSWORD_LOGIN_FAIL */, {
|
|
5010
|
+
category: "auth" /* AUTH */,
|
|
5011
|
+
label: "password"
|
|
5012
|
+
});
|
|
5013
|
+
if (error instanceof APIError) {
|
|
5014
|
+
const body = error.response;
|
|
5015
|
+
return {
|
|
5016
|
+
success: false,
|
|
5017
|
+
statusCode: error.statusCode,
|
|
5018
|
+
message: apiErrorMessage(error),
|
|
5019
|
+
errorCode: body?.error_code,
|
|
5020
|
+
retryAfter: typeof body?.retry_after === "number" ? body.retry_after : void 0
|
|
5021
|
+
};
|
|
5022
|
+
}
|
|
5023
|
+
return { success: false, message: "Failed to sign in" };
|
|
5024
|
+
}
|
|
5025
|
+
},
|
|
5026
|
+
[setStoredEmail, redirectManager, router]
|
|
5027
|
+
);
|
|
4776
5028
|
const refreshToken = (0, import_react16.useCallback)(async () => {
|
|
4777
5029
|
const access = await auth.refreshNow();
|
|
4778
5030
|
if (access) {
|
|
@@ -4827,6 +5079,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4827
5079
|
clearSavedEmail: clearStoredEmail,
|
|
4828
5080
|
requestOTP,
|
|
4829
5081
|
verifyOTP,
|
|
5082
|
+
login,
|
|
4830
5083
|
refreshToken,
|
|
4831
5084
|
logout,
|
|
4832
5085
|
saveRedirectUrl: redirectManager.setRedirect,
|
|
@@ -4849,6 +5102,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4849
5102
|
clearStoredEmail,
|
|
4850
5103
|
requestOTP,
|
|
4851
5104
|
verifyOTP,
|
|
5105
|
+
login,
|
|
4852
5106
|
refreshToken,
|
|
4853
5107
|
logout,
|
|
4854
5108
|
redirectManager,
|
|
@@ -4892,6 +5146,10 @@ var defaultAuthState = {
|
|
|
4892
5146
|
authLogger.warn("useAuth: verifyOTP called outside AuthProvider");
|
|
4893
5147
|
return { success: false, message: "AuthProvider not available" };
|
|
4894
5148
|
}, "verifyOTP"),
|
|
5149
|
+
login: /* @__PURE__ */ __name(async () => {
|
|
5150
|
+
authLogger.warn("useAuth: login called outside AuthProvider");
|
|
5151
|
+
return { success: false, message: "AuthProvider not available" };
|
|
5152
|
+
}, "login"),
|
|
4895
5153
|
refreshToken: /* @__PURE__ */ __name(async () => {
|
|
4896
5154
|
authLogger.warn("useAuth: refreshToken called outside AuthProvider");
|
|
4897
5155
|
return { success: false, message: "AuthProvider not available" };
|