eocene-auth-sdk 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -5
- package/dist/index.js +198 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ type WaasPasswordResetRequestResult = {
|
|
|
67
67
|
type WaasPasswordResetConfirmResult = {
|
|
68
68
|
ok: true;
|
|
69
69
|
passwordEnabled: boolean;
|
|
70
|
+
recoveryEmail?: string;
|
|
71
|
+
recovery?: WaasWalletRecoveryStatus;
|
|
70
72
|
};
|
|
71
73
|
type WaasRecoveryEmailBindRequestResult = {
|
|
72
74
|
ok: true;
|
|
@@ -151,7 +153,7 @@ declare class WaasClient {
|
|
|
151
153
|
requestRecoveryEmailBind(email: string): Promise<WaasRecoveryEmailBindRequestResult>;
|
|
152
154
|
confirmRecoveryEmailBind(code: string, email?: string): Promise<WaasRecoveryEmailBindConfirmResult>;
|
|
153
155
|
clearPassword(password: string): Promise<void>;
|
|
154
|
-
requestPasswordReset(channel?: WaasPasswordResetChannel): Promise<WaasPasswordResetRequestResult>;
|
|
156
|
+
requestPasswordReset(channel?: WaasPasswordResetChannel, email?: string): Promise<WaasPasswordResetRequestResult>;
|
|
155
157
|
confirmPasswordReset(code: string, newPassword?: string | null): Promise<WaasPasswordResetConfirmResult>;
|
|
156
158
|
signMessage(message: string, opts?: {
|
|
157
159
|
password?: string;
|
|
@@ -332,9 +334,10 @@ type PasswordSettingsProps = {
|
|
|
332
334
|
recoveryCode?: string;
|
|
333
335
|
}) => Promise<void>;
|
|
334
336
|
onSubmitClear: (password: string) => Promise<void>;
|
|
335
|
-
onRequestResetCode?: (channel?: WaasPasswordResetChannel) => Promise<void>;
|
|
337
|
+
onRequestResetCode?: (channel?: WaasPasswordResetChannel, email?: string) => Promise<void>;
|
|
336
338
|
onSubmitReset?: (code: string, newPassword?: string | null) => Promise<void>;
|
|
337
339
|
onRequestRecoveryEmailBind?: (email: string) => Promise<void>;
|
|
340
|
+
onConfirmRecoveryEmailBind?: (code: string, email?: string) => Promise<void>;
|
|
338
341
|
onClose: () => void;
|
|
339
342
|
};
|
|
340
343
|
type LoginPanelProps = {
|
|
@@ -454,6 +457,7 @@ declare class AuthClient {
|
|
|
454
457
|
private localSessionNeedsRefresh;
|
|
455
458
|
restoreIfNeeded(): boolean;
|
|
456
459
|
restoreSession(): Promise<boolean>;
|
|
460
|
+
private bootstrapRefreshToken;
|
|
457
461
|
private performRestoreSession;
|
|
458
462
|
logout(): void;
|
|
459
463
|
setPassword(password: string, currentPassword?: string, recoveryBind?: {
|
|
@@ -463,8 +467,9 @@ declare class AuthClient {
|
|
|
463
467
|
clearPassword(password: string): Promise<void>;
|
|
464
468
|
requestRecoveryEmailBind(email: string): Promise<WaasRecoveryEmailBindRequestResult>;
|
|
465
469
|
confirmRecoveryEmailBind(code: string, email?: string): Promise<WaasRecoveryEmailBindConfirmResult>;
|
|
466
|
-
requestPasswordReset(channel?: WaasPasswordResetChannel): Promise<WaasPasswordResetRequestResult>;
|
|
470
|
+
requestPasswordReset(channel?: WaasPasswordResetChannel, email?: string): Promise<WaasPasswordResetRequestResult>;
|
|
467
471
|
confirmPasswordReset(code: string, newPassword?: string | null): Promise<WaasPasswordResetConfirmResult>;
|
|
472
|
+
refreshUser(): Promise<AuthUser | null>;
|
|
468
473
|
}
|
|
469
474
|
|
|
470
475
|
/**
|
|
@@ -514,7 +519,7 @@ type AuthContextValue = {
|
|
|
514
519
|
recoveryCode?: string;
|
|
515
520
|
}) => Promise<void>;
|
|
516
521
|
clearPassword: (password: string) => Promise<void>;
|
|
517
|
-
requestPasswordReset: (channel?: WaasPasswordResetChannel) => Promise<WaasPasswordResetRequestResult>;
|
|
522
|
+
requestPasswordReset: (channel?: WaasPasswordResetChannel, email?: string) => Promise<WaasPasswordResetRequestResult>;
|
|
518
523
|
confirmPasswordReset: (code: string, newPassword?: string | null) => Promise<WaasPasswordResetConfirmResult>;
|
|
519
524
|
requestRecoveryEmailBind: (email: string) => Promise<WaasRecoveryEmailBindRequestResult>;
|
|
520
525
|
confirmRecoveryEmailBind: (code: string, email?: string) => Promise<WaasRecoveryEmailBindConfirmResult>;
|
|
@@ -564,7 +569,7 @@ declare function authConfigFromViteEnv(env?: object): AuthSdkConfig;
|
|
|
564
569
|
|
|
565
570
|
declare function SignConfirmModal({ open, request, labels, password, busy, error, locked, onPasswordChange, onApprove, onReject, onOpenSetPassword, onOpenResetPassword, }: SignApprovalProps): react.JSX.Element | null;
|
|
566
571
|
|
|
567
|
-
declare function SetPasswordModal({ open, passwordEnabled, initialMode, recovery, labels, busy, sendingResetCode, resetSent, sendingRecoveryBindCode, recoveryBindSent, error, onSubmitSet, onSubmitClear, onRequestResetCode, onSubmitReset, onRequestRecoveryEmailBind, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
|
|
572
|
+
declare function SetPasswordModal({ open, passwordEnabled, initialMode, recovery, labels, busy, sendingResetCode, resetSent, sendingRecoveryBindCode, recoveryBindSent, error, onSubmitSet, onSubmitClear, onRequestResetCode, onSubmitReset, onRequestRecoveryEmailBind, onConfirmRecoveryEmailBind, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
|
|
568
573
|
|
|
569
574
|
/**
|
|
570
575
|
* EOCENE Research mark and lockup. Inline SVG (no asset fetch); transparent
|
package/dist/index.js
CHANGED
|
@@ -2983,14 +2983,17 @@ var WaasClient = class {
|
|
|
2983
2983
|
});
|
|
2984
2984
|
if (this.state) this.state.passwordEnabled = false;
|
|
2985
2985
|
}
|
|
2986
|
-
async requestPasswordReset(channel) {
|
|
2986
|
+
async requestPasswordReset(channel, email) {
|
|
2987
2987
|
this.requireSession();
|
|
2988
|
+
const payload = {};
|
|
2989
|
+
if (channel) payload.channel = channel;
|
|
2990
|
+
if (email && email.trim()) payload.email = email.trim();
|
|
2988
2991
|
return this.authed(
|
|
2989
2992
|
`${this.controlBaseUrl}/wallet/password/reset/request`,
|
|
2990
2993
|
{
|
|
2991
2994
|
method: "POST",
|
|
2992
2995
|
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2993
|
-
body: JSON.stringify(
|
|
2996
|
+
body: JSON.stringify(payload)
|
|
2994
2997
|
}
|
|
2995
2998
|
);
|
|
2996
2999
|
}
|
|
@@ -3004,7 +3007,10 @@ var WaasClient = class {
|
|
|
3004
3007
|
body: JSON.stringify({ code, newPassword })
|
|
3005
3008
|
}
|
|
3006
3009
|
);
|
|
3007
|
-
if (this.state)
|
|
3010
|
+
if (this.state) {
|
|
3011
|
+
this.state.passwordEnabled = out.passwordEnabled;
|
|
3012
|
+
if (out.recovery) this.state.recovery = out.recovery;
|
|
3013
|
+
}
|
|
3008
3014
|
return out;
|
|
3009
3015
|
}
|
|
3010
3016
|
async signMessage(message, opts) {
|
|
@@ -3072,24 +3078,67 @@ var WaasClient = class {
|
|
|
3072
3078
|
};
|
|
3073
3079
|
|
|
3074
3080
|
// src/client/storage.ts
|
|
3081
|
+
function safeGet(storage, key) {
|
|
3082
|
+
if (!storage) return null;
|
|
3083
|
+
try {
|
|
3084
|
+
return storage.getItem(key);
|
|
3085
|
+
} catch {
|
|
3086
|
+
return null;
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
function safeSet(storage, key, value) {
|
|
3090
|
+
if (!storage) return false;
|
|
3091
|
+
try {
|
|
3092
|
+
storage.setItem(key, value);
|
|
3093
|
+
return true;
|
|
3094
|
+
} catch {
|
|
3095
|
+
return false;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
function safeRemove(storage, key) {
|
|
3099
|
+
if (!storage) return;
|
|
3100
|
+
try {
|
|
3101
|
+
storage.removeItem(key);
|
|
3102
|
+
} catch {
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
function localOrNull() {
|
|
3106
|
+
return typeof localStorage !== "undefined" ? localStorage : void 0;
|
|
3107
|
+
}
|
|
3108
|
+
function sessionOrNull() {
|
|
3109
|
+
return typeof sessionStorage !== "undefined" ? sessionStorage : void 0;
|
|
3110
|
+
}
|
|
3075
3111
|
function loadPersistedState(storageKey = DEFAULT_STORAGE_KEY) {
|
|
3076
|
-
|
|
3112
|
+
const localRaw = safeGet(localOrNull(), storageKey);
|
|
3113
|
+
if (localRaw) {
|
|
3114
|
+
try {
|
|
3115
|
+
return JSON.parse(localRaw);
|
|
3116
|
+
} catch {
|
|
3117
|
+
safeRemove(localOrNull(), storageKey);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
const sessionRaw = safeGet(sessionOrNull(), storageKey);
|
|
3121
|
+
if (!sessionRaw) return null;
|
|
3077
3122
|
try {
|
|
3078
|
-
const
|
|
3079
|
-
if (
|
|
3080
|
-
|
|
3123
|
+
const parsed = JSON.parse(sessionRaw);
|
|
3124
|
+
if (safeSet(localOrNull(), storageKey, sessionRaw)) {
|
|
3125
|
+
safeRemove(sessionOrNull(), storageKey);
|
|
3126
|
+
}
|
|
3127
|
+
return parsed;
|
|
3081
3128
|
} catch {
|
|
3129
|
+
safeRemove(sessionOrNull(), storageKey);
|
|
3082
3130
|
return null;
|
|
3083
3131
|
}
|
|
3084
3132
|
}
|
|
3085
|
-
function persistDeviceState(state, storageKey = DEFAULT_STORAGE_KEY) {
|
|
3086
|
-
if (typeof sessionStorage === "undefined") return;
|
|
3133
|
+
function persistDeviceState(state, storageKey = DEFAULT_STORAGE_KEY, opts) {
|
|
3087
3134
|
if (!state?.sessionToken) {
|
|
3088
|
-
|
|
3135
|
+
clearPersistedState(storageKey);
|
|
3089
3136
|
return;
|
|
3090
3137
|
}
|
|
3138
|
+
const existingRefresh = opts?.refreshToken !== void 0 ? opts.refreshToken : loadPersistedState(storageKey)?.refreshToken;
|
|
3091
3139
|
const payload = {
|
|
3092
3140
|
sessionToken: state.sessionToken,
|
|
3141
|
+
...existingRefresh ? { refreshToken: existingRefresh } : {},
|
|
3093
3142
|
principalId: state.principalId,
|
|
3094
3143
|
email: state.email,
|
|
3095
3144
|
walletId: state.walletId,
|
|
@@ -3097,11 +3146,16 @@ function persistDeviceState(state, storageKey = DEFAULT_STORAGE_KEY) {
|
|
|
3097
3146
|
epoch: state.epoch,
|
|
3098
3147
|
passwordEnabled: state.passwordEnabled
|
|
3099
3148
|
};
|
|
3100
|
-
|
|
3149
|
+
const serialized = JSON.stringify(payload);
|
|
3150
|
+
if (safeSet(localOrNull(), storageKey, serialized)) {
|
|
3151
|
+
safeRemove(sessionOrNull(), storageKey);
|
|
3152
|
+
} else {
|
|
3153
|
+
safeSet(sessionOrNull(), storageKey, serialized);
|
|
3154
|
+
}
|
|
3101
3155
|
}
|
|
3102
3156
|
function clearPersistedState(storageKey = DEFAULT_STORAGE_KEY) {
|
|
3103
|
-
|
|
3104
|
-
|
|
3157
|
+
safeRemove(localOrNull(), storageKey);
|
|
3158
|
+
safeRemove(sessionOrNull(), storageKey);
|
|
3105
3159
|
}
|
|
3106
3160
|
|
|
3107
3161
|
// src/client/telegramMiniApp.ts
|
|
@@ -3221,8 +3275,12 @@ var AuthClient = class {
|
|
|
3221
3275
|
getProvider: async () => this.getProvider()
|
|
3222
3276
|
};
|
|
3223
3277
|
}
|
|
3224
|
-
persist() {
|
|
3225
|
-
persistDeviceState(
|
|
3278
|
+
persist(refreshToken) {
|
|
3279
|
+
persistDeviceState(
|
|
3280
|
+
this.client.getState(),
|
|
3281
|
+
this.storageKey,
|
|
3282
|
+
refreshToken !== void 0 ? { refreshToken } : void 0
|
|
3283
|
+
);
|
|
3226
3284
|
}
|
|
3227
3285
|
async fetchOAuthProviders() {
|
|
3228
3286
|
const base = this.config.controlBaseUrl.replace(/\/$/, "");
|
|
@@ -3358,6 +3416,7 @@ var AuthClient = class {
|
|
|
3358
3416
|
this.persist();
|
|
3359
3417
|
this.active = true;
|
|
3360
3418
|
this.provider = null;
|
|
3419
|
+
this.bootstrapRefreshToken(decodeURIComponent(sessionToken));
|
|
3361
3420
|
if (typeof sessionStorage !== "undefined") {
|
|
3362
3421
|
sessionStorage.removeItem(this.oauthPendingKey);
|
|
3363
3422
|
}
|
|
@@ -3410,6 +3469,24 @@ var AuthClient = class {
|
|
|
3410
3469
|
});
|
|
3411
3470
|
return this.restorePromise;
|
|
3412
3471
|
}
|
|
3472
|
+
bootstrapRefreshToken(sessionToken) {
|
|
3473
|
+
if (!this.config.projectId || !sessionToken) return;
|
|
3474
|
+
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3475
|
+
void fetch(`${base}/auth/session/refresh`, {
|
|
3476
|
+
method: "POST",
|
|
3477
|
+
credentials: "include",
|
|
3478
|
+
headers: {
|
|
3479
|
+
"content-type": "application/json",
|
|
3480
|
+
authorization: `Bearer ${sessionToken}`
|
|
3481
|
+
},
|
|
3482
|
+
body: JSON.stringify({ projectId: this.config.projectId })
|
|
3483
|
+
}).then((res) => res.ok ? res.json() : null).then((result) => {
|
|
3484
|
+
if (result?.refreshToken && this.active) {
|
|
3485
|
+
this.persist(result.refreshToken);
|
|
3486
|
+
}
|
|
3487
|
+
}).catch(() => {
|
|
3488
|
+
});
|
|
3489
|
+
}
|
|
3413
3490
|
async performRestoreSession() {
|
|
3414
3491
|
const restoreLocalIfCurrent = () => this.restoreLocalSession() && !this.localSessionNeedsRefresh();
|
|
3415
3492
|
if (restoreLocalIfCurrent()) return true;
|
|
@@ -3418,21 +3495,26 @@ var AuthClient = class {
|
|
|
3418
3495
|
try {
|
|
3419
3496
|
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3420
3497
|
const url = `${base}/auth/session/refresh`;
|
|
3421
|
-
const
|
|
3498
|
+
const saved = loadPersistedState(this.storageKey);
|
|
3499
|
+
const storedRefresh = saved?.refreshToken;
|
|
3500
|
+
const body = JSON.stringify({
|
|
3501
|
+
projectId: this.config.projectId,
|
|
3502
|
+
...storedRefresh ? { refreshToken: storedRefresh } : {}
|
|
3503
|
+
});
|
|
3422
3504
|
let res = await fetch(url, {
|
|
3423
3505
|
method: "POST",
|
|
3424
3506
|
credentials: "include",
|
|
3425
3507
|
headers: { "content-type": "application/json" },
|
|
3426
3508
|
body
|
|
3427
3509
|
});
|
|
3428
|
-
const legacyToken =
|
|
3510
|
+
const legacyToken = saved?.sessionToken;
|
|
3429
3511
|
const legacyExpMs = legacyToken ? sessionTokenExpMs(legacyToken) : null;
|
|
3430
3512
|
if (res.status === 401 && legacyToken && legacyExpMs != null && legacyExpMs > Date.now()) {
|
|
3431
3513
|
res = await fetch(url, {
|
|
3432
3514
|
method: "POST",
|
|
3433
3515
|
credentials: "include",
|
|
3434
3516
|
headers: { "content-type": "application/json", authorization: `Bearer ${legacyToken}` },
|
|
3435
|
-
body
|
|
3517
|
+
body: JSON.stringify({ projectId: this.config.projectId })
|
|
3436
3518
|
});
|
|
3437
3519
|
}
|
|
3438
3520
|
const result = await res.json().catch(() => ({}));
|
|
@@ -3441,7 +3523,7 @@ var AuthClient = class {
|
|
|
3441
3523
|
await this.client.ensureWallet({
|
|
3442
3524
|
telegramInitData: getTelegramInitData() ?? void 0
|
|
3443
3525
|
});
|
|
3444
|
-
this.persist();
|
|
3526
|
+
this.persist(result.refreshToken);
|
|
3445
3527
|
this.active = true;
|
|
3446
3528
|
this.provider = null;
|
|
3447
3529
|
return true;
|
|
@@ -3457,13 +3539,17 @@ var AuthClient = class {
|
|
|
3457
3539
|
}
|
|
3458
3540
|
logout() {
|
|
3459
3541
|
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3542
|
+
const storedRefresh = loadPersistedState(this.storageKey)?.refreshToken;
|
|
3460
3543
|
try {
|
|
3461
3544
|
void fetch(`${base}/auth/session/logout`, {
|
|
3462
3545
|
method: "POST",
|
|
3463
3546
|
credentials: "include",
|
|
3464
3547
|
keepalive: true,
|
|
3465
3548
|
headers: { "content-type": "application/json" },
|
|
3466
|
-
body: JSON.stringify({
|
|
3549
|
+
body: JSON.stringify({
|
|
3550
|
+
projectId: this.config.projectId,
|
|
3551
|
+
...storedRefresh ? { refreshToken: storedRefresh } : {}
|
|
3552
|
+
})
|
|
3467
3553
|
}).catch(() => {
|
|
3468
3554
|
});
|
|
3469
3555
|
} finally {
|
|
@@ -3486,14 +3572,36 @@ var AuthClient = class {
|
|
|
3486
3572
|
this.persist();
|
|
3487
3573
|
return out;
|
|
3488
3574
|
}
|
|
3489
|
-
async requestPasswordReset(channel) {
|
|
3490
|
-
return this.client.requestPasswordReset(channel);
|
|
3575
|
+
async requestPasswordReset(channel, email) {
|
|
3576
|
+
return this.client.requestPasswordReset(channel, email);
|
|
3491
3577
|
}
|
|
3492
3578
|
async confirmPasswordReset(code, newPassword) {
|
|
3493
3579
|
const out = await this.client.confirmPasswordReset(code, newPassword);
|
|
3494
3580
|
this.persist();
|
|
3495
3581
|
return out;
|
|
3496
3582
|
}
|
|
3583
|
+
async refreshUser() {
|
|
3584
|
+
const s = this.client.getState();
|
|
3585
|
+
if (!s?.sessionToken) return null;
|
|
3586
|
+
try {
|
|
3587
|
+
const me = await this.client.fetchMe();
|
|
3588
|
+
const cur = this.client.getState();
|
|
3589
|
+
if (cur && me.wallet) {
|
|
3590
|
+
this.client.hydrate({
|
|
3591
|
+
...cur,
|
|
3592
|
+
email: me.email ?? cur.email,
|
|
3593
|
+
walletId: me.wallet.walletId,
|
|
3594
|
+
address: me.wallet.address,
|
|
3595
|
+
epoch: me.wallet.epoch,
|
|
3596
|
+
passwordEnabled: me.wallet.passwordEnabled,
|
|
3597
|
+
recovery: me.wallet.recovery
|
|
3598
|
+
});
|
|
3599
|
+
this.persist();
|
|
3600
|
+
}
|
|
3601
|
+
} catch {
|
|
3602
|
+
}
|
|
3603
|
+
return this.getUser();
|
|
3604
|
+
}
|
|
3497
3605
|
};
|
|
3498
3606
|
|
|
3499
3607
|
// src/provider/createProvider.ts
|
|
@@ -3808,6 +3916,7 @@ function SetPasswordModal({
|
|
|
3808
3916
|
onRequestResetCode,
|
|
3809
3917
|
onSubmitReset,
|
|
3810
3918
|
onRequestRecoveryEmailBind,
|
|
3919
|
+
onConfirmRecoveryEmailBind,
|
|
3811
3920
|
onClose
|
|
3812
3921
|
}) {
|
|
3813
3922
|
const [password, setPassword] = useState("");
|
|
@@ -3868,9 +3977,11 @@ function SetPasswordModal({
|
|
|
3868
3977
|
return () => window.clearInterval(timer);
|
|
3869
3978
|
}, [open, recoveryBindSent]);
|
|
3870
3979
|
if (!open) return null;
|
|
3980
|
+
const hasBoundRecovery = Boolean(recovery?.hasRecovery);
|
|
3871
3981
|
const needsRecoveryBind = Boolean(
|
|
3872
|
-
mode === "set" &&
|
|
3982
|
+
mode === "set" && !hasBoundRecovery && onRequestRecoveryEmailBind
|
|
3873
3983
|
);
|
|
3984
|
+
const needsResetEmailInput = Boolean(mode === "reset" && !hasBoundRecovery);
|
|
3874
3985
|
const mismatch = password.length > 0 && confirm.length > 0 && password !== confirm;
|
|
3875
3986
|
const normalizedCode = code.trim();
|
|
3876
3987
|
const validCode = /^\d{6}$/.test(normalizedCode);
|
|
@@ -3878,10 +3989,11 @@ function SetPasswordModal({
|
|
|
3878
3989
|
const validBindCode = /^\d{6}$/.test(normalizedBindCode);
|
|
3879
3990
|
const validRecoveryEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(recoveryEmail.trim());
|
|
3880
3991
|
const canSet = password.length >= 6 && password === confirm && (!passwordEnabled || current.length > 0) && (!needsRecoveryBind || validRecoveryEmail && validBindCode) && !busy;
|
|
3992
|
+
const canBindEmailOnly = needsRecoveryBind && validRecoveryEmail && validBindCode && password.length === 0 && Boolean(onConfirmRecoveryEmailBind) && !busy;
|
|
3881
3993
|
const canClear = passwordEnabled && current.length > 0 && !busy;
|
|
3882
|
-
const canResetSet = passwordEnabled && validCode && password.length >= 6 && password === confirm && !busy;
|
|
3883
|
-
const canResetClear = passwordEnabled && validCode && !busy;
|
|
3884
|
-
const resetHintText = mode === "reset" && resetSent ? (resetSent.channel === "telegram" ? labels.passwordSettingsCodeSentTelegram : labels.passwordSettingsCodeSentEmail).replace("{target}", resetSent.maskedTarget) : mode === "reset" ? labels.passwordSettingsResetHint : needsRecoveryBind ? recoveryBindSent ? labels.passwordSettingsCodeSentEmail.replace("{target}", recoveryBindSent.maskedTarget) : labels.passwordSettingsBindEmailHint : passwordEnabled ? labels.passwordSettingsEnabledHint : labels.passwordSettingsDisabledHint;
|
|
3994
|
+
const canResetSet = passwordEnabled && validCode && password.length >= 6 && password === confirm && (!needsResetEmailInput || validRecoveryEmail) && !busy;
|
|
3995
|
+
const canResetClear = passwordEnabled && validCode && (!needsResetEmailInput || validRecoveryEmail) && !busy;
|
|
3996
|
+
const resetHintText = mode === "reset" && resetSent ? (resetSent.channel === "telegram" ? labels.passwordSettingsCodeSentTelegram : labels.passwordSettingsCodeSentEmail).replace("{target}", resetSent.maskedTarget) : mode === "reset" ? needsResetEmailInput ? labels.passwordSettingsBindEmailHint : labels.passwordSettingsResetHint : needsRecoveryBind ? recoveryBindSent ? labels.passwordSettingsCodeSentEmail.replace("{target}", recoveryBindSent.maskedTarget) : labels.passwordSettingsBindEmailHint : passwordEnabled ? labels.passwordSettingsEnabledHint : labels.passwordSettingsDisabledHint;
|
|
3885
3997
|
const dualChannels = Boolean(recovery?.channels && recovery.channels.length > 1);
|
|
3886
3998
|
const effectiveResetChannel = selectedChannel ?? recovery?.defaultChannel ?? void 0;
|
|
3887
3999
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
@@ -4100,6 +4212,21 @@ function SetPasswordModal({
|
|
|
4100
4212
|
}
|
|
4101
4213
|
)
|
|
4102
4214
|
] }) : null,
|
|
4215
|
+
needsResetEmailInput ? /* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4216
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsBindEmailLabel }),
|
|
4217
|
+
/* @__PURE__ */ jsx(
|
|
4218
|
+
"input",
|
|
4219
|
+
{
|
|
4220
|
+
type: "email",
|
|
4221
|
+
autoComplete: "email",
|
|
4222
|
+
placeholder: labels.passwordSettingsBindEmailPlaceholder,
|
|
4223
|
+
value: recoveryEmail,
|
|
4224
|
+
onChange: (e) => setRecoveryEmail(e.target.value),
|
|
4225
|
+
disabled: busy,
|
|
4226
|
+
autoFocus: true
|
|
4227
|
+
}
|
|
4228
|
+
)
|
|
4229
|
+
] }) : null,
|
|
4103
4230
|
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4104
4231
|
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
|
|
4105
4232
|
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
|
|
@@ -4114,7 +4241,7 @@ function SetPasswordModal({
|
|
|
4114
4241
|
value: code,
|
|
4115
4242
|
onChange: (e) => setCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
|
|
4116
4243
|
disabled: busy,
|
|
4117
|
-
autoFocus:
|
|
4244
|
+
autoFocus: !needsResetEmailInput
|
|
4118
4245
|
}
|
|
4119
4246
|
),
|
|
4120
4247
|
/* @__PURE__ */ jsx(
|
|
@@ -4122,8 +4249,11 @@ function SetPasswordModal({
|
|
|
4122
4249
|
{
|
|
4123
4250
|
type: "button",
|
|
4124
4251
|
className: "auth-sdk-code-send-btn",
|
|
4125
|
-
disabled: busy || sendingResetCode || cooldownLeft > 0,
|
|
4126
|
-
onClick: () => void onRequestResetCode?.(
|
|
4252
|
+
disabled: busy || sendingResetCode || cooldownLeft > 0 || needsResetEmailInput && !validRecoveryEmail,
|
|
4253
|
+
onClick: () => void onRequestResetCode?.(
|
|
4254
|
+
effectiveResetChannel,
|
|
4255
|
+
needsResetEmailInput ? recoveryEmail.trim() : void 0
|
|
4256
|
+
),
|
|
4127
4257
|
children: sendingResetCode ? labels.passwordSettingsSendingCode : cooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
|
|
4128
4258
|
"{seconds}",
|
|
4129
4259
|
String(cooldownLeft)
|
|
@@ -4184,7 +4314,15 @@ function SetPasswordModal({
|
|
|
4184
4314
|
children: labels.passwordSettingsCancel
|
|
4185
4315
|
}
|
|
4186
4316
|
),
|
|
4187
|
-
mode === "set" ? /* @__PURE__ */ jsx(
|
|
4317
|
+
mode === "set" ? canBindEmailOnly ? /* @__PURE__ */ jsx(
|
|
4318
|
+
"button",
|
|
4319
|
+
{
|
|
4320
|
+
type: "button",
|
|
4321
|
+
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
4322
|
+
onClick: () => void onConfirmRecoveryEmailBind?.(normalizedBindCode, recoveryEmail.trim()),
|
|
4323
|
+
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsSave
|
|
4324
|
+
}
|
|
4325
|
+
) : /* @__PURE__ */ jsx(
|
|
4188
4326
|
"button",
|
|
4189
4327
|
{
|
|
4190
4328
|
type: "button",
|
|
@@ -4644,8 +4782,8 @@ function AuthProvider({
|
|
|
4644
4782
|
[bump]
|
|
4645
4783
|
);
|
|
4646
4784
|
const requestPasswordReset = useCallback(
|
|
4647
|
-
async (channel) => {
|
|
4648
|
-
return clientRef.current.requestPasswordReset(channel);
|
|
4785
|
+
async (channel, email) => {
|
|
4786
|
+
return clientRef.current.requestPasswordReset(channel, email);
|
|
4649
4787
|
},
|
|
4650
4788
|
[]
|
|
4651
4789
|
);
|
|
@@ -4669,11 +4807,15 @@ function AuthProvider({
|
|
|
4669
4807
|
},
|
|
4670
4808
|
[bump]
|
|
4671
4809
|
);
|
|
4672
|
-
const openPasswordSettings = useCallback(
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4810
|
+
const openPasswordSettings = useCallback(
|
|
4811
|
+
(initialMode) => {
|
|
4812
|
+
setPasswordError(null);
|
|
4813
|
+
setPasswordInitialMode(initialMode ?? "set");
|
|
4814
|
+
setPasswordSettingsOpen(true);
|
|
4815
|
+
void clientRef.current?.refreshUser().then(() => bump());
|
|
4816
|
+
},
|
|
4817
|
+
[bump]
|
|
4818
|
+
);
|
|
4677
4819
|
const closePasswordSettings = useCallback(() => {
|
|
4678
4820
|
if (passwordBusy || sendingResetCode || sendingRecoveryBindCode) return;
|
|
4679
4821
|
setPasswordSettingsOpen(false);
|
|
@@ -4774,6 +4916,22 @@ function AuthProvider({
|
|
|
4774
4916
|
},
|
|
4775
4917
|
[requestRecoveryEmailBind, labels]
|
|
4776
4918
|
);
|
|
4919
|
+
const onConfirmRecoveryEmailBind = useCallback(
|
|
4920
|
+
async (code, email) => {
|
|
4921
|
+
setPasswordBusy(true);
|
|
4922
|
+
setPasswordError(null);
|
|
4923
|
+
try {
|
|
4924
|
+
await confirmRecoveryEmailBind(code, email);
|
|
4925
|
+
setRecoveryBindSent(null);
|
|
4926
|
+
setPasswordSettingsOpen(false);
|
|
4927
|
+
} catch (e) {
|
|
4928
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4929
|
+
} finally {
|
|
4930
|
+
setPasswordBusy(false);
|
|
4931
|
+
}
|
|
4932
|
+
},
|
|
4933
|
+
[confirmRecoveryEmailBind, labels]
|
|
4934
|
+
);
|
|
4777
4935
|
const onSubmitClear = useCallback(
|
|
4778
4936
|
async (pw) => {
|
|
4779
4937
|
setPasswordBusy(true);
|
|
@@ -4791,11 +4949,11 @@ function AuthProvider({
|
|
|
4791
4949
|
[clearPassword, markPendingSignPasswordState, labels]
|
|
4792
4950
|
);
|
|
4793
4951
|
const onRequestResetCode = useCallback(
|
|
4794
|
-
async (channel) => {
|
|
4952
|
+
async (channel, email) => {
|
|
4795
4953
|
setSendingResetCode(true);
|
|
4796
4954
|
setPasswordError(null);
|
|
4797
4955
|
try {
|
|
4798
|
-
const out = await requestPasswordReset(channel);
|
|
4956
|
+
const out = await requestPasswordReset(channel, email);
|
|
4799
4957
|
setResetSent({
|
|
4800
4958
|
channel: out.channel,
|
|
4801
4959
|
maskedTarget: out.maskedTarget,
|
|
@@ -4844,6 +5002,7 @@ function AuthProvider({
|
|
|
4844
5002
|
onRequestResetCode,
|
|
4845
5003
|
onSubmitReset,
|
|
4846
5004
|
onRequestRecoveryEmailBind,
|
|
5005
|
+
onConfirmRecoveryEmailBind,
|
|
4847
5006
|
onClose: closePasswordSettings
|
|
4848
5007
|
};
|
|
4849
5008
|
const value = useMemo(
|