eocene-auth-sdk 0.2.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +51 -10
- package/dist/index.d.ts +50 -14
- package/dist/index.js +346 -43
- package/dist/index.js.map +1 -1
- package/dist/styles.css +20 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2814,7 +2814,7 @@ function createWaasEip1193Provider(client, options) {
|
|
|
2814
2814
|
|
|
2815
2815
|
// ../eocene-worker/packages/sdk/src/index.ts
|
|
2816
2816
|
async function http(url, init) {
|
|
2817
|
-
const res = await fetch(url, init);
|
|
2817
|
+
const res = await fetch(url, { credentials: "include", ...init });
|
|
2818
2818
|
const body = await res.json().catch(() => ({}));
|
|
2819
2819
|
if (!res.ok) {
|
|
2820
2820
|
throw new WaasHttpError(res.status, url, body);
|
|
@@ -3027,8 +3027,39 @@ function clearPersistedState(storageKey = DEFAULT_STORAGE_KEY) {
|
|
|
3027
3027
|
sessionStorage.removeItem(storageKey);
|
|
3028
3028
|
}
|
|
3029
3029
|
|
|
3030
|
+
// src/client/telegramMiniApp.ts
|
|
3031
|
+
function readWebApp() {
|
|
3032
|
+
if (typeof window === "undefined") return null;
|
|
3033
|
+
const tg = window.Telegram;
|
|
3034
|
+
return tg?.WebApp ?? null;
|
|
3035
|
+
}
|
|
3036
|
+
function isTelegramMiniApp() {
|
|
3037
|
+
return Boolean(readWebApp()?.initData);
|
|
3038
|
+
}
|
|
3039
|
+
function getTelegramInitData() {
|
|
3040
|
+
return readWebApp()?.initData || null;
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3030
3043
|
// src/client/AuthClient.ts
|
|
3031
|
-
var SOCIAL_METHODS = ["google", "twitter", "github", "apple"];
|
|
3044
|
+
var SOCIAL_METHODS = ["google", "twitter", "github", "apple", "telegram"];
|
|
3045
|
+
var RESTORE_EXPIRY_BUFFER_MS = 6e4;
|
|
3046
|
+
var RESTORE_REFRESH_WITHIN_MS = 15 * 60 * 1e3;
|
|
3047
|
+
function sessionTokenExpMs(sessionToken) {
|
|
3048
|
+
try {
|
|
3049
|
+
const encoded = sessionToken.split(".")[1];
|
|
3050
|
+
if (!encoded) return null;
|
|
3051
|
+
const base64 = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
3052
|
+
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
3053
|
+
const payload = JSON.parse(atob(padded));
|
|
3054
|
+
return typeof payload.exp === "number" && Number.isFinite(payload.exp) ? payload.exp * 1e3 : null;
|
|
3055
|
+
} catch {
|
|
3056
|
+
return null;
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
function hasUsableSessionToken(sessionToken) {
|
|
3060
|
+
const expMs = sessionTokenExpMs(sessionToken);
|
|
3061
|
+
return expMs != null && expMs > Date.now() + RESTORE_EXPIRY_BUFFER_MS;
|
|
3062
|
+
}
|
|
3032
3063
|
var AuthClient = class {
|
|
3033
3064
|
config;
|
|
3034
3065
|
storageKey;
|
|
@@ -3037,6 +3068,7 @@ var AuthClient = class {
|
|
|
3037
3068
|
provider = null;
|
|
3038
3069
|
chainId;
|
|
3039
3070
|
active = false;
|
|
3071
|
+
restorePromise = null;
|
|
3040
3072
|
requestApproval;
|
|
3041
3073
|
onSessionExpired;
|
|
3042
3074
|
constructor(options) {
|
|
@@ -3060,7 +3092,7 @@ var AuthClient = class {
|
|
|
3060
3092
|
const saved = loadPersistedState(this.storageKey);
|
|
3061
3093
|
if (saved?.sessionToken) {
|
|
3062
3094
|
this.client.hydrate(saved);
|
|
3063
|
-
|
|
3095
|
+
this.active = Boolean(saved.address && hasUsableSessionToken(saved.sessionToken));
|
|
3064
3096
|
}
|
|
3065
3097
|
}
|
|
3066
3098
|
setRequestApproval(fn) {
|
|
@@ -3147,6 +3179,9 @@ var AuthClient = class {
|
|
|
3147
3179
|
}
|
|
3148
3180
|
}
|
|
3149
3181
|
async login(method) {
|
|
3182
|
+
if (method === "telegram" && getTelegramInitData()) {
|
|
3183
|
+
return this.loginTelegramMiniApp();
|
|
3184
|
+
}
|
|
3150
3185
|
const status = await this.fetchOAuthProviders();
|
|
3151
3186
|
if (status.providers[method]) {
|
|
3152
3187
|
if (typeof sessionStorage !== "undefined") {
|
|
@@ -3174,7 +3209,7 @@ var AuthClient = class {
|
|
|
3174
3209
|
`${method} OAuth is not configured on eocene-worker (providers.${method}=false). Set GOOGLE_CLIENT_ID/SECRET in eocene-worker/.env and restart, or set EOCENE_OAUTH_FALLBACK_DEV=true for local mock.`
|
|
3175
3210
|
);
|
|
3176
3211
|
}
|
|
3177
|
-
const email = `${method}@
|
|
3212
|
+
const email = `${method}@eocene.local`;
|
|
3178
3213
|
await this.client.loginDev(email, method, {
|
|
3179
3214
|
projectId: this.config.projectId,
|
|
3180
3215
|
asDeveloper: this.config.asDeveloper
|
|
@@ -3197,6 +3232,37 @@ var AuthClient = class {
|
|
|
3197
3232
|
this.provider = null;
|
|
3198
3233
|
return wallet;
|
|
3199
3234
|
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Silent login for apps running inside the Telegram webview: no redirect,
|
|
3237
|
+
* no popup — the bot-signed `initData` is exchanged directly for a session.
|
|
3238
|
+
* `initData` defaults to `window.Telegram.WebApp.initData`; pass it
|
|
3239
|
+
* explicitly only in tests.
|
|
3240
|
+
*/
|
|
3241
|
+
async loginTelegramMiniApp(initData) {
|
|
3242
|
+
const data = initData ?? getTelegramInitData();
|
|
3243
|
+
if (!data) {
|
|
3244
|
+
throw new Error("Not inside a Telegram Mini App (window.Telegram.WebApp.initData is empty).");
|
|
3245
|
+
}
|
|
3246
|
+
if (!this.config.projectId) {
|
|
3247
|
+
throw new Error("Telegram Mini App login requires config.projectId.");
|
|
3248
|
+
}
|
|
3249
|
+
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3250
|
+
const res = await fetch(`${base}/auth/telegram/miniapp`, {
|
|
3251
|
+
method: "POST",
|
|
3252
|
+
headers: { "content-type": "application/json" },
|
|
3253
|
+
body: JSON.stringify({ initData: data, projectId: this.config.projectId })
|
|
3254
|
+
});
|
|
3255
|
+
const body = await res.json().catch(() => ({}));
|
|
3256
|
+
if (!res.ok || !body.sessionToken) {
|
|
3257
|
+
throw new Error(body.error ?? `telegram miniapp login HTTP ${res.status}`);
|
|
3258
|
+
}
|
|
3259
|
+
await this.client.loginWithSessionToken(body.sessionToken);
|
|
3260
|
+
const wallet = await this.client.ensureWallet();
|
|
3261
|
+
this.persist();
|
|
3262
|
+
this.active = true;
|
|
3263
|
+
this.provider = null;
|
|
3264
|
+
return { ...wallet, provider: "telegram" };
|
|
3265
|
+
}
|
|
3200
3266
|
async completeOAuthFromHash(hashOrSearch) {
|
|
3201
3267
|
const raw = hashOrSearch.startsWith("#") || hashOrSearch.startsWith("?") ? hashOrSearch.slice(1) : hashOrSearch;
|
|
3202
3268
|
const params = new URLSearchParams(raw);
|
|
@@ -3239,16 +3305,86 @@ var AuthClient = class {
|
|
|
3239
3305
|
this.persist();
|
|
3240
3306
|
}
|
|
3241
3307
|
}
|
|
3242
|
-
|
|
3243
|
-
const saved = loadPersistedState(this.storageKey);
|
|
3244
|
-
if (!saved?.sessionToken || !saved.address) return false;
|
|
3308
|
+
restoreLocalSession() {
|
|
3309
|
+
const saved = loadPersistedState(this.storageKey) ?? this.client.getState();
|
|
3310
|
+
if (!saved?.sessionToken || !saved.address || !hasUsableSessionToken(saved.sessionToken)) return false;
|
|
3245
3311
|
this.client.hydrate(saved);
|
|
3246
3312
|
this.active = true;
|
|
3247
3313
|
this.provider = null;
|
|
3248
3314
|
return true;
|
|
3249
3315
|
}
|
|
3316
|
+
localSessionNeedsRefresh() {
|
|
3317
|
+
const token = loadPersistedState(this.storageKey)?.sessionToken ?? this.client.getState()?.sessionToken;
|
|
3318
|
+
const expMs = token ? sessionTokenExpMs(token) : null;
|
|
3319
|
+
return expMs == null || expMs <= Date.now() + RESTORE_REFRESH_WITHIN_MS;
|
|
3320
|
+
}
|
|
3321
|
+
restoreIfNeeded() {
|
|
3322
|
+
return this.restoreLocalSession();
|
|
3323
|
+
}
|
|
3324
|
+
restoreSession() {
|
|
3325
|
+
if (this.restorePromise) return this.restorePromise;
|
|
3326
|
+
this.restorePromise = this.performRestoreSession().finally(() => {
|
|
3327
|
+
this.restorePromise = null;
|
|
3328
|
+
});
|
|
3329
|
+
return this.restorePromise;
|
|
3330
|
+
}
|
|
3331
|
+
async performRestoreSession() {
|
|
3332
|
+
const restoreLocalIfCurrent = () => this.restoreLocalSession() && !this.localSessionNeedsRefresh();
|
|
3333
|
+
if (restoreLocalIfCurrent()) return true;
|
|
3334
|
+
const restore = async () => {
|
|
3335
|
+
if (restoreLocalIfCurrent()) return true;
|
|
3336
|
+
try {
|
|
3337
|
+
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3338
|
+
const url = `${base}/auth/session/refresh`;
|
|
3339
|
+
const body = JSON.stringify({ projectId: this.config.projectId });
|
|
3340
|
+
let res = await fetch(url, {
|
|
3341
|
+
method: "POST",
|
|
3342
|
+
credentials: "include",
|
|
3343
|
+
headers: { "content-type": "application/json" },
|
|
3344
|
+
body
|
|
3345
|
+
});
|
|
3346
|
+
const legacyToken = loadPersistedState(this.storageKey)?.sessionToken;
|
|
3347
|
+
const legacyExpMs = legacyToken ? sessionTokenExpMs(legacyToken) : null;
|
|
3348
|
+
if (res.status === 401 && legacyToken && legacyExpMs != null && legacyExpMs > Date.now()) {
|
|
3349
|
+
res = await fetch(url, {
|
|
3350
|
+
method: "POST",
|
|
3351
|
+
credentials: "include",
|
|
3352
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${legacyToken}` },
|
|
3353
|
+
body
|
|
3354
|
+
});
|
|
3355
|
+
}
|
|
3356
|
+
const result = await res.json().catch(() => ({}));
|
|
3357
|
+
if (!res.ok || !result.sessionToken) throw new Error(`session refresh HTTP ${res.status}`);
|
|
3358
|
+
await this.client.loginWithSessionToken(result.sessionToken);
|
|
3359
|
+
await this.client.ensureWallet();
|
|
3360
|
+
this.persist();
|
|
3361
|
+
this.active = true;
|
|
3362
|
+
this.provider = null;
|
|
3363
|
+
return true;
|
|
3364
|
+
} catch {
|
|
3365
|
+
if (!this.restoreLocalSession()) this.markActive(false);
|
|
3366
|
+
return false;
|
|
3367
|
+
}
|
|
3368
|
+
};
|
|
3369
|
+
if (typeof navigator !== "undefined" && navigator.locks) {
|
|
3370
|
+
return navigator.locks.request(`eocene:restore:${this.storageKey}`, restore);
|
|
3371
|
+
}
|
|
3372
|
+
return restore();
|
|
3373
|
+
}
|
|
3250
3374
|
logout() {
|
|
3251
|
-
this.
|
|
3375
|
+
const base = resolveControlAbsoluteUrl(this.config.controlBaseUrl);
|
|
3376
|
+
try {
|
|
3377
|
+
void fetch(`${base}/auth/session/logout`, {
|
|
3378
|
+
method: "POST",
|
|
3379
|
+
credentials: "include",
|
|
3380
|
+
keepalive: true,
|
|
3381
|
+
headers: { "content-type": "application/json" },
|
|
3382
|
+
body: JSON.stringify({ projectId: this.config.projectId })
|
|
3383
|
+
}).catch(() => {
|
|
3384
|
+
});
|
|
3385
|
+
} finally {
|
|
3386
|
+
this.markActive(false);
|
|
3387
|
+
}
|
|
3252
3388
|
}
|
|
3253
3389
|
async setPassword(password, currentPassword) {
|
|
3254
3390
|
await this.client.setPassword(password, currentPassword);
|
|
@@ -3320,7 +3456,7 @@ function formatSignAuthError(err, labels) {
|
|
|
3320
3456
|
}
|
|
3321
3457
|
function EoceneMark({
|
|
3322
3458
|
size = 28,
|
|
3323
|
-
title = "
|
|
3459
|
+
title = "EOCENE Research",
|
|
3324
3460
|
...props
|
|
3325
3461
|
}) {
|
|
3326
3462
|
return /* @__PURE__ */ jsxs(
|
|
@@ -3360,29 +3496,67 @@ function EoceneWordmark({
|
|
|
3360
3496
|
className,
|
|
3361
3497
|
markSize = 28
|
|
3362
3498
|
}) {
|
|
3499
|
+
const nameSize = Math.round(markSize * 0.5);
|
|
3500
|
+
const researchSize = Math.round(markSize * 0.3);
|
|
3363
3501
|
return /* @__PURE__ */ jsxs(
|
|
3364
3502
|
"span",
|
|
3365
3503
|
{
|
|
3366
3504
|
className,
|
|
3505
|
+
role: "img",
|
|
3506
|
+
"aria-label": "EOCENE Research",
|
|
3367
3507
|
style: {
|
|
3368
3508
|
display: "inline-flex",
|
|
3369
3509
|
alignItems: "center",
|
|
3370
|
-
gap:
|
|
3371
|
-
fontWeight: 700,
|
|
3372
|
-
letterSpacing: "-0.03em",
|
|
3510
|
+
gap: Math.round(markSize * 0.32),
|
|
3373
3511
|
lineHeight: 1
|
|
3374
3512
|
},
|
|
3375
3513
|
children: [
|
|
3376
|
-
/* @__PURE__ */ jsx(EoceneMark, { size: markSize }),
|
|
3377
|
-
/* @__PURE__ */ jsxs(
|
|
3378
|
-
"
|
|
3379
|
-
|
|
3380
|
-
|
|
3514
|
+
/* @__PURE__ */ jsx(EoceneMark, { size: markSize, "aria-hidden": true }),
|
|
3515
|
+
/* @__PURE__ */ jsxs(
|
|
3516
|
+
"span",
|
|
3517
|
+
{
|
|
3518
|
+
style: {
|
|
3519
|
+
display: "flex",
|
|
3520
|
+
flexDirection: "column",
|
|
3521
|
+
justifyContent: "center",
|
|
3522
|
+
gap: 3
|
|
3523
|
+
},
|
|
3524
|
+
children: [
|
|
3525
|
+
/* @__PURE__ */ jsx(
|
|
3526
|
+
"span",
|
|
3527
|
+
{
|
|
3528
|
+
style: {
|
|
3529
|
+
fontSize: nameSize,
|
|
3530
|
+
fontWeight: 700,
|
|
3531
|
+
letterSpacing: "0.16em",
|
|
3532
|
+
textTransform: "uppercase",
|
|
3533
|
+
color: "var(--auth-sdk-text, currentColor)",
|
|
3534
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif"
|
|
3535
|
+
},
|
|
3536
|
+
children: "EOCENE"
|
|
3537
|
+
}
|
|
3538
|
+
),
|
|
3539
|
+
/* @__PURE__ */ jsx(
|
|
3540
|
+
"span",
|
|
3541
|
+
{
|
|
3542
|
+
style: {
|
|
3543
|
+
fontSize: researchSize,
|
|
3544
|
+
fontWeight: 400,
|
|
3545
|
+
letterSpacing: "0.02em",
|
|
3546
|
+
color: "var(--auth-sdk-muted, #8ba3b8)",
|
|
3547
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif"
|
|
3548
|
+
},
|
|
3549
|
+
children: "Research"
|
|
3550
|
+
}
|
|
3551
|
+
)
|
|
3552
|
+
]
|
|
3553
|
+
}
|
|
3554
|
+
)
|
|
3381
3555
|
]
|
|
3382
3556
|
}
|
|
3383
3557
|
);
|
|
3384
3558
|
}
|
|
3385
|
-
var DEFAULT_METHODS = ["google", "twitter", "github", "apple"];
|
|
3559
|
+
var DEFAULT_METHODS = ["google", "twitter", "github", "apple", "telegram"];
|
|
3386
3560
|
function methodLabel(method, labels) {
|
|
3387
3561
|
switch (method) {
|
|
3388
3562
|
case "google":
|
|
@@ -3393,6 +3567,8 @@ function methodLabel(method, labels) {
|
|
|
3393
3567
|
return labels.loginGithub;
|
|
3394
3568
|
case "apple":
|
|
3395
3569
|
return labels.loginApple;
|
|
3570
|
+
case "telegram":
|
|
3571
|
+
return labels.loginTelegram;
|
|
3396
3572
|
}
|
|
3397
3573
|
}
|
|
3398
3574
|
function AuthLoginPanel({
|
|
@@ -3403,11 +3579,20 @@ function AuthLoginPanel({
|
|
|
3403
3579
|
error,
|
|
3404
3580
|
onLogin
|
|
3405
3581
|
}) {
|
|
3582
|
+
const [pendingMethod, setPendingMethod] = useState(null);
|
|
3583
|
+
const [submitted, setSubmitted] = useState(false);
|
|
3584
|
+
const busy = submitted || pendingMethod != null && loadingMethod === pendingMethod;
|
|
3585
|
+
useEffect(() => {
|
|
3586
|
+
if (pendingMethod == null || busy) return;
|
|
3587
|
+
const onKeyDown = (e) => {
|
|
3588
|
+
if (e.key === "Escape") setPendingMethod(null);
|
|
3589
|
+
};
|
|
3590
|
+
window.addEventListener("keydown", onKeyDown);
|
|
3591
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
3592
|
+
}, [pendingMethod, busy]);
|
|
3406
3593
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root auth-sdk-login", children: [
|
|
3407
|
-
/* @__PURE__ */
|
|
3408
|
-
|
|
3409
|
-
/* @__PURE__ */ jsx("p", { className: "auth-sdk-login-title", children: labels.loginTitle })
|
|
3410
|
-
] }),
|
|
3594
|
+
/* @__PURE__ */ jsx("div", { className: "auth-sdk-login-brand", children: /* @__PURE__ */ jsx(EoceneWordmark, { markSize: 32 }) }),
|
|
3595
|
+
/* @__PURE__ */ jsx("p", { className: "auth-sdk-login-title", children: labels.loginTitle }),
|
|
3411
3596
|
/* @__PURE__ */ jsx("div", { className: "auth-sdk-login-stack", children: loadingMethods ? (
|
|
3412
3597
|
// Skeleton rows while the enabled-methods list loads — avoids
|
|
3413
3598
|
// flashing every provider then removing the disabled ones.
|
|
@@ -3416,20 +3601,73 @@ function AuthLoginPanel({
|
|
|
3416
3601
|
/* @__PURE__ */ jsx("span", { className: "auth-sdk-login-skeleton", "aria-hidden": true })
|
|
3417
3602
|
] })
|
|
3418
3603
|
) : methods.length === 0 ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-login-empty", children: labels.loginNoMethods }) : methods.map((method) => {
|
|
3419
|
-
const
|
|
3604
|
+
const methodBusy = loadingMethod === method;
|
|
3420
3605
|
return /* @__PURE__ */ jsx(
|
|
3421
3606
|
"button",
|
|
3422
3607
|
{
|
|
3423
3608
|
type: "button",
|
|
3424
3609
|
className: "auth-sdk-login-btn",
|
|
3425
|
-
disabled: loadingMethod != null,
|
|
3426
|
-
onClick: () =>
|
|
3427
|
-
|
|
3610
|
+
disabled: pendingMethod != null || loadingMethod != null,
|
|
3611
|
+
onClick: () => {
|
|
3612
|
+
setSubmitted(false);
|
|
3613
|
+
setPendingMethod(method);
|
|
3614
|
+
},
|
|
3615
|
+
children: methodBusy ? labels.loginConnecting : methodLabel(method, labels)
|
|
3428
3616
|
},
|
|
3429
3617
|
method
|
|
3430
3618
|
);
|
|
3431
3619
|
}) }),
|
|
3432
|
-
error ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-login-error", children: error }) : null
|
|
3620
|
+
error ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-login-error", children: error }) : null,
|
|
3621
|
+
pendingMethod ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
3622
|
+
/* @__PURE__ */ jsx(
|
|
3623
|
+
"div",
|
|
3624
|
+
{
|
|
3625
|
+
className: "auth-sdk-backdrop",
|
|
3626
|
+
onClick: busy ? void 0 : () => setPendingMethod(null),
|
|
3627
|
+
"aria-hidden": true
|
|
3628
|
+
}
|
|
3629
|
+
),
|
|
3630
|
+
/* @__PURE__ */ jsxs(
|
|
3631
|
+
"div",
|
|
3632
|
+
{
|
|
3633
|
+
className: "auth-sdk-sign-panel",
|
|
3634
|
+
role: "dialog",
|
|
3635
|
+
"aria-modal": "true",
|
|
3636
|
+
"aria-labelledby": "auth-sdk-login-confirm-title",
|
|
3637
|
+
children: [
|
|
3638
|
+
/* @__PURE__ */ jsx("h2", { id: "auth-sdk-login-confirm-title", className: "auth-sdk-sign-title", children: labels.loginConfirmTitle.replace("{provider}", methodLabel(pendingMethod, labels)) }),
|
|
3639
|
+
/* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-subtitle", children: labels.loginConfirmBody }),
|
|
3640
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-actions", children: [
|
|
3641
|
+
/* @__PURE__ */ jsx(
|
|
3642
|
+
"button",
|
|
3643
|
+
{
|
|
3644
|
+
type: "button",
|
|
3645
|
+
className: "auth-sdk-btn auth-sdk-btn-secondary",
|
|
3646
|
+
onClick: () => setPendingMethod(null),
|
|
3647
|
+
disabled: busy,
|
|
3648
|
+
children: labels.loginConfirmCancel
|
|
3649
|
+
}
|
|
3650
|
+
),
|
|
3651
|
+
/* @__PURE__ */ jsx(
|
|
3652
|
+
"button",
|
|
3653
|
+
{
|
|
3654
|
+
type: "button",
|
|
3655
|
+
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
3656
|
+
autoFocus: true,
|
|
3657
|
+
onClick: () => {
|
|
3658
|
+
if (busy) return;
|
|
3659
|
+
setSubmitted(true);
|
|
3660
|
+
onLogin(pendingMethod);
|
|
3661
|
+
},
|
|
3662
|
+
disabled: busy,
|
|
3663
|
+
children: busy ? labels.loginConnecting : labels.loginConfirmContinue
|
|
3664
|
+
}
|
|
3665
|
+
)
|
|
3666
|
+
] })
|
|
3667
|
+
]
|
|
3668
|
+
}
|
|
3669
|
+
)
|
|
3670
|
+
] }) : null
|
|
3433
3671
|
] });
|
|
3434
3672
|
}
|
|
3435
3673
|
function SetPasswordModal({
|
|
@@ -3756,9 +3994,14 @@ var DEFAULT_LABELS = {
|
|
|
3756
3994
|
loginTwitter: "X",
|
|
3757
3995
|
loginGithub: "GitHub",
|
|
3758
3996
|
loginApple: "Apple",
|
|
3997
|
+
loginTelegram: "Telegram",
|
|
3759
3998
|
loginConnecting: "Connecting\u2026",
|
|
3760
3999
|
loginError: "Sign-in failed",
|
|
3761
4000
|
loginNoMethods: "No sign-in methods are enabled for this app yet.",
|
|
4001
|
+
loginConfirmTitle: "Continue with {provider}?",
|
|
4002
|
+
loginConfirmBody: "You'll leave this page to sign in, then return here.",
|
|
4003
|
+
loginConfirmContinue: "Continue",
|
|
4004
|
+
loginConfirmCancel: "Cancel",
|
|
3762
4005
|
oauthWorking: "Completing sign-in\u2026",
|
|
3763
4006
|
oauthFailed: "OAuth failed",
|
|
3764
4007
|
oauthBack: "Back to login",
|
|
@@ -3825,13 +4068,16 @@ function AuthProvider({
|
|
|
3825
4068
|
);
|
|
3826
4069
|
const [tick, setTick] = useState(0);
|
|
3827
4070
|
const [ready, setReady] = useState(false);
|
|
4071
|
+
const mountedRef = useRef(false);
|
|
3828
4072
|
const sessionExpiredRef = useRef(void 0);
|
|
3829
4073
|
sessionExpiredRef.current = onSessionExpired;
|
|
3830
4074
|
const handleSessionExpired = useCallback(() => {
|
|
3831
4075
|
pendingSignRef.current?.resolve(false);
|
|
3832
4076
|
pendingSignRef.current = null;
|
|
3833
|
-
|
|
3834
|
-
|
|
4077
|
+
if (mountedRef.current) {
|
|
4078
|
+
setPendingSign(null);
|
|
4079
|
+
setTick((n) => n + 1);
|
|
4080
|
+
}
|
|
3835
4081
|
sessionExpiredRef.current?.();
|
|
3836
4082
|
}, []);
|
|
3837
4083
|
const clientRef = useRef(null);
|
|
@@ -3843,26 +4089,52 @@ function AuthProvider({
|
|
|
3843
4089
|
onSessionExpired: handleSessionExpired
|
|
3844
4090
|
});
|
|
3845
4091
|
}
|
|
4092
|
+
useEffect(() => {
|
|
4093
|
+
mountedRef.current = true;
|
|
4094
|
+
return () => {
|
|
4095
|
+
mountedRef.current = false;
|
|
4096
|
+
};
|
|
4097
|
+
}, []);
|
|
3846
4098
|
useEffect(() => {
|
|
3847
4099
|
clientRef.current?.setRequestApproval(approvalFn);
|
|
3848
4100
|
}, [approvalFn]);
|
|
3849
4101
|
useEffect(() => {
|
|
3850
4102
|
const c = clientRef.current;
|
|
3851
4103
|
if (!c) return;
|
|
3852
|
-
if (c.config.controlBaseUrl !== config.controlBaseUrl || c.config.oauthReturnTo !== config.oauthReturnTo) {
|
|
4104
|
+
if (c.config.controlBaseUrl !== config.controlBaseUrl || c.config.oauthReturnTo !== config.oauthReturnTo || c.config.projectId !== config.projectId || c.config.chainId !== config.chainId || c.config.asDeveloper !== config.asDeveloper || c.config.storageKey !== config.storageKey || c.config.oauthPendingKey !== config.oauthPendingKey || c.config.allowDevLoginFallback !== config.allowDevLoginFallback) {
|
|
3853
4105
|
clientRef.current = new AuthClient({
|
|
3854
4106
|
config,
|
|
4107
|
+
chainId: config.chainId,
|
|
3855
4108
|
requestApproval: approvalFn,
|
|
3856
4109
|
onSessionExpired: handleSessionExpired
|
|
3857
4110
|
});
|
|
4111
|
+
setReady(false);
|
|
3858
4112
|
setTick((n) => n + 1);
|
|
3859
4113
|
}
|
|
3860
4114
|
}, [config, approvalFn, handleSessionExpired]);
|
|
3861
4115
|
useEffect(() => {
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
4116
|
+
let alive = true;
|
|
4117
|
+
const c = clientRef.current;
|
|
4118
|
+
if (!c) return;
|
|
4119
|
+
setReady(false);
|
|
4120
|
+
void c.restoreSession().then(() => {
|
|
4121
|
+
if (!alive || clientRef.current !== c) return;
|
|
4122
|
+
setTick((n) => n + 1);
|
|
4123
|
+
setReady(true);
|
|
4124
|
+
});
|
|
4125
|
+
return () => {
|
|
4126
|
+
alive = false;
|
|
4127
|
+
};
|
|
4128
|
+
}, [
|
|
4129
|
+
config.controlBaseUrl,
|
|
4130
|
+
config.oauthReturnTo,
|
|
4131
|
+
config.projectId,
|
|
4132
|
+
config.chainId,
|
|
4133
|
+
config.asDeveloper,
|
|
4134
|
+
config.storageKey,
|
|
4135
|
+
config.oauthPendingKey,
|
|
4136
|
+
config.allowDevLoginFallback
|
|
4137
|
+
]);
|
|
3866
4138
|
const [availableMethods, setAvailableMethods] = useState(null);
|
|
3867
4139
|
useEffect(() => {
|
|
3868
4140
|
let alive = true;
|
|
@@ -3876,7 +4148,9 @@ function AuthProvider({
|
|
|
3876
4148
|
alive = false;
|
|
3877
4149
|
};
|
|
3878
4150
|
}, [config.controlBaseUrl, config.projectId]);
|
|
3879
|
-
const bump = useCallback(() =>
|
|
4151
|
+
const bump = useCallback(() => {
|
|
4152
|
+
if (mountedRef.current) setTick((n) => n + 1);
|
|
4153
|
+
}, []);
|
|
3880
4154
|
const login = useCallback(
|
|
3881
4155
|
async (args) => {
|
|
3882
4156
|
const result = await clientRef.current.login(args.method);
|
|
@@ -3885,6 +4159,11 @@ function AuthProvider({
|
|
|
3885
4159
|
},
|
|
3886
4160
|
[bump]
|
|
3887
4161
|
);
|
|
4162
|
+
const loginTelegramMiniApp = useCallback(async () => {
|
|
4163
|
+
const result = await clientRef.current.loginTelegramMiniApp();
|
|
4164
|
+
bump();
|
|
4165
|
+
return result;
|
|
4166
|
+
}, [bump]);
|
|
3888
4167
|
const logout = useCallback(() => {
|
|
3889
4168
|
clientRef.current.logout();
|
|
3890
4169
|
bump();
|
|
@@ -3901,6 +4180,12 @@ function AuthProvider({
|
|
|
3901
4180
|
bump();
|
|
3902
4181
|
return ok;
|
|
3903
4182
|
}, [bump]);
|
|
4183
|
+
const restoreSession = useCallback(async () => {
|
|
4184
|
+
const c = clientRef.current;
|
|
4185
|
+
const ok = await c.restoreSession();
|
|
4186
|
+
if (clientRef.current === c) bump();
|
|
4187
|
+
return ok;
|
|
4188
|
+
}, [bump]);
|
|
3904
4189
|
const completeOAuthFromHash = useCallback(
|
|
3905
4190
|
async (hashOrSearch) => {
|
|
3906
4191
|
const result = await clientRef.current.completeOAuthFromHash(hashOrSearch);
|
|
@@ -4041,9 +4326,11 @@ function AuthProvider({
|
|
|
4041
4326
|
user,
|
|
4042
4327
|
passwordEnabled,
|
|
4043
4328
|
login,
|
|
4329
|
+
loginTelegramMiniApp,
|
|
4044
4330
|
logout,
|
|
4045
4331
|
markActive,
|
|
4046
4332
|
restoreIfNeeded,
|
|
4333
|
+
restoreSession,
|
|
4047
4334
|
completeOAuthFromHash,
|
|
4048
4335
|
takeOAuthReturnPath,
|
|
4049
4336
|
getProvider,
|
|
@@ -4064,9 +4351,11 @@ function AuthProvider({
|
|
|
4064
4351
|
user,
|
|
4065
4352
|
passwordEnabled,
|
|
4066
4353
|
login,
|
|
4354
|
+
loginTelegramMiniApp,
|
|
4067
4355
|
logout,
|
|
4068
4356
|
markActive,
|
|
4069
4357
|
restoreIfNeeded,
|
|
4358
|
+
restoreSession,
|
|
4070
4359
|
completeOAuthFromHash,
|
|
4071
4360
|
takeOAuthReturnPath,
|
|
4072
4361
|
getProvider,
|
|
@@ -4123,13 +4412,13 @@ function AuthOAuthCallback({
|
|
|
4123
4412
|
if (children) return /* @__PURE__ */ jsx(Fragment, { children: children({ phase, error }) });
|
|
4124
4413
|
if (error) {
|
|
4125
4414
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root auth-sdk-oauth-page", children: [
|
|
4126
|
-
/* @__PURE__ */ jsx(
|
|
4415
|
+
/* @__PURE__ */ jsx(EoceneWordmark, { markSize: 40 }),
|
|
4127
4416
|
/* @__PURE__ */ jsx("p", { className: "auth-sdk-oauth-error", children: error }),
|
|
4128
4417
|
/* @__PURE__ */ jsx("a", { className: "auth-sdk-link", href: onBackHref, children: labels.oauthBack })
|
|
4129
4418
|
] });
|
|
4130
4419
|
}
|
|
4131
4420
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root auth-sdk-oauth-page", children: [
|
|
4132
|
-
/* @__PURE__ */ jsx(
|
|
4421
|
+
/* @__PURE__ */ jsx(EoceneWordmark, { markSize: 40 }),
|
|
4133
4422
|
/* @__PURE__ */ jsx("p", { children: phase })
|
|
4134
4423
|
] });
|
|
4135
4424
|
}
|
|
@@ -4154,14 +4443,28 @@ function flagAny(env, keys, defaultOn = false) {
|
|
|
4154
4443
|
}
|
|
4155
4444
|
function authConfigFromViteEnv(env = {}) {
|
|
4156
4445
|
const e = env;
|
|
4157
|
-
const oauthReturnTo = readAny(e, [
|
|
4158
|
-
|
|
4159
|
-
|
|
4446
|
+
const oauthReturnTo = readAny(e, [
|
|
4447
|
+
"VITE_EOCENE_OAUTH_RETURN_TO",
|
|
4448
|
+
"EOCENE_OAUTH_RETURN_TO",
|
|
4449
|
+
"VITE_WAAS_OAUTH_RETURN_TO",
|
|
4450
|
+
"WAAS_OAUTH_RETURN_TO"
|
|
4451
|
+
]);
|
|
4452
|
+
const projectId = readAny(e, ["VITE_EOCENE_PROJECT_ID", "EOCENE_PROJECT_ID", "VITE_WAAS_PROJECT_ID", "WAAS_PROJECT_ID"]) || void 0;
|
|
4453
|
+
const chainRaw = readAny(e, ["VITE_EOCENE_CHAIN_ID", "EOCENE_CHAIN_ID", "VITE_WAAS_CHAIN_ID", "WAAS_CHAIN_ID"]);
|
|
4160
4454
|
const chainId = chainRaw && Number.isFinite(Number(chainRaw)) ? Number(chainRaw) : void 0;
|
|
4161
4455
|
return {
|
|
4162
|
-
controlBaseUrl: readAny(e, ["EOCENE_CONTROL_URL", "WAAS_CONTROL_URL"]) || DEFAULT_CONTROL_BASE_URL,
|
|
4456
|
+
controlBaseUrl: readAny(e, ["VITE_EOCENE_CONTROL_URL", "EOCENE_CONTROL_URL", "VITE_WAAS_CONTROL_URL", "WAAS_CONTROL_URL"]) || DEFAULT_CONTROL_BASE_URL,
|
|
4163
4457
|
oauthReturnTo: oauthReturnTo || (typeof window !== "undefined" ? `${window.location.origin}/login/eocene-callback` : "http://127.0.0.1:5173/login/eocene-callback"),
|
|
4164
|
-
allowDevLoginFallback: flagAny(
|
|
4458
|
+
allowDevLoginFallback: flagAny(
|
|
4459
|
+
e,
|
|
4460
|
+
[
|
|
4461
|
+
"VITE_EOCENE_OAUTH_FALLBACK_DEV",
|
|
4462
|
+
"EOCENE_OAUTH_FALLBACK_DEV",
|
|
4463
|
+
"VITE_WAAS_OAUTH_FALLBACK_DEV",
|
|
4464
|
+
"WAAS_OAUTH_FALLBACK_DEV"
|
|
4465
|
+
],
|
|
4466
|
+
false
|
|
4467
|
+
),
|
|
4165
4468
|
projectId,
|
|
4166
4469
|
chainId,
|
|
4167
4470
|
storageKey: DEFAULT_STORAGE_KEY,
|
|
@@ -4182,6 +4485,6 @@ function authConfigFromViteEnv(env = {}) {
|
|
|
4182
4485
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4183
4486
|
*/
|
|
4184
4487
|
|
|
4185
|
-
export { AuthClient, AuthLoginPanel, AuthOAuthCallback, AuthProvider, DEFAULT_CONTROL_BASE_URL, DEFAULT_LABELS, DEFAULT_OAUTH_PENDING_KEY, DEFAULT_STORAGE_KEY, EoceneMark, EoceneWordmark, SetPasswordModal, SignConfirmModal, authConfigFromViteEnv, createAuthEip1193Provider, isWaasHttpError, resolveControlAbsoluteUrl, useAuthContext as useAuth };
|
|
4488
|
+
export { AuthClient, AuthLoginPanel, AuthOAuthCallback, AuthProvider, DEFAULT_CONTROL_BASE_URL, DEFAULT_LABELS, DEFAULT_OAUTH_PENDING_KEY, DEFAULT_STORAGE_KEY, EoceneMark, EoceneWordmark, SetPasswordModal, SignConfirmModal, authConfigFromViteEnv, createAuthEip1193Provider, getTelegramInitData, isTelegramMiniApp, isWaasHttpError, resolveControlAbsoluteUrl, useAuthContext as useAuth };
|
|
4186
4489
|
//# sourceMappingURL=index.js.map
|
|
4187
4490
|
//# sourceMappingURL=index.js.map
|