@xk2800/nextjs-template 0.7.2-beta.7 → 0.7.2-beta.9
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/README.md +1 -0
- package/components/auth/forms/signup-form.tsx +3 -0
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +1 -1
- package/components/dashboard/admin/users/impersonation-tab.tsx +1 -1
- package/components/dashboard/layout/app-sidebar.tsx +7 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/layout/top-nav.tsx +14 -33
- package/components/dashboard/settings/activity-logs-card.tsx +1 -1
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +64 -13
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +25 -18
- package/dist/activity/queries.d.ts +25 -18
- package/dist/activity/queries.js +73 -20
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +15 -13
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +44 -13
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +7 -7
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +247 -224
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +262 -239
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +14 -23
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +54 -12
- package/dist/auth/helpers.d.ts +54 -12
- package/dist/auth/helpers.js +276 -242
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +68 -47
- package/dist/auth/index.d.ts +68 -47
- package/dist/auth/index.js +242 -221
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1215 -2527
- package/dist/auth-client/index.d.ts +1215 -2527
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-M6Y2XNJC.mjs → chunk-3BH6BVBQ.mjs} +16 -6
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-J5XRJ2GW.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/{chunk-J5XRJ2GW.mjs.map → chunk-DWLMCMXF.mjs.map} +1 -1
- package/dist/{chunk-AOSJUQQG.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/{chunk-AOSJUQQG.mjs.map → chunk-EXMUANQ3.mjs.map} +1 -1
- package/dist/{chunk-NOFQCVHC.mjs → chunk-IH6CMZIN.mjs} +195 -215
- package/dist/chunk-IH6CMZIN.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-TMANA7KL.mjs → chunk-NJBRKKLK.mjs} +9 -6
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-JRDMU6I2.mjs → chunk-QDUPSU5O.mjs} +3 -3
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-2BKXG4MG.mjs → chunk-S23GC776.mjs} +38 -27
- package/dist/chunk-S23GC776.mjs.map +1 -0
- package/dist/{chunk-CRDC62BU.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/{chunk-CRDC62BU.mjs.map → chunk-TIR7KHXL.mjs.map} +1 -1
- package/dist/{chunk-JSB36AY6.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +60 -11
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +13 -3
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +60 -11
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +12 -2
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +60 -11
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +3 -2
- package/dist/settings/queries.d.ts +3 -2
- package/dist/settings/queries.js +46 -12
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +24 -19
- package/dist/users/queries.d.ts +24 -19
- package/dist/users/queries.js +48 -13
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +8 -6
- package/dist/users/queries.mjs.map +1 -1
- package/lib/auth/client.ts +22 -2
- package/lib/utils/request-info.ts +7 -3
- package/package.json +65 -59
- package/scripts/check-deps.mjs +67 -0
- package/dist/chunk-2BKXG4MG.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-JRDMU6I2.mjs.map +0 -1
- package/dist/chunk-JSB36AY6.mjs.map +0 -1
- package/dist/chunk-M6Y2XNJC.mjs.map +0 -1
- package/dist/chunk-NOFQCVHC.mjs.map +0 -1
- package/dist/chunk-RLZ7F7ZY.mjs +0 -30
- package/dist/chunk-RLZ7F7ZY.mjs.map +0 -1
- package/dist/chunk-TMANA7KL.mjs.map +0 -1
package/dist/api/marketing.js
CHANGED
|
@@ -49,8 +49,13 @@ var __spreadValues = (a, b) => {
|
|
|
49
49
|
return a;
|
|
50
50
|
};
|
|
51
51
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
52
|
-
var __esm = (fn, res) => function __init() {
|
|
53
|
-
|
|
52
|
+
var __esm = (fn, res, err) => function __init() {
|
|
53
|
+
if (err) throw err[0];
|
|
54
|
+
try {
|
|
55
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw err = [e], e;
|
|
58
|
+
}
|
|
54
59
|
};
|
|
55
60
|
var __export = (target, all) => {
|
|
56
61
|
for (var name in all)
|
|
@@ -292,7 +297,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
292
297
|
// Set by better-auth's admin plugin while this session is an admin
|
|
293
298
|
// impersonating another user; holds the impersonating admin's user id.
|
|
294
299
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
295
|
-
})
|
|
300
|
+
}, (table) => [
|
|
301
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
302
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
303
|
+
]);
|
|
296
304
|
var accounts = pgCore.pgTable("account", {
|
|
297
305
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
298
306
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -341,7 +349,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
341
349
|
});
|
|
342
350
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
343
351
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
344
|
-
|
|
352
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
353
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
354
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
355
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
345
356
|
action: ActivityActionEnum("action").notNull(),
|
|
346
357
|
description: pgCore.text("description").notNull(),
|
|
347
358
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -357,7 +368,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
357
368
|
country: pgCore.text("country"),
|
|
358
369
|
city: pgCore.text("city"),
|
|
359
370
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
360
|
-
})
|
|
371
|
+
}, (table) => [
|
|
372
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
373
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
374
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
375
|
+
]);
|
|
361
376
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
362
377
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
363
378
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -472,7 +487,9 @@ var envSchema = zod.z.object({
|
|
|
472
487
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
473
488
|
// Sender for every transactional email. Must be on a domain verified in
|
|
474
489
|
// your Resend account.
|
|
475
|
-
|
|
490
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
491
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
492
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
476
493
|
// Display name for this deployment — shown as the authenticator-app label
|
|
477
494
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
478
495
|
// this in their own .env; defaults to the template name.
|
|
@@ -482,6 +499,9 @@ var envSchema = zod.z.object({
|
|
|
482
499
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
483
500
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
484
501
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
502
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
503
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
504
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
485
505
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
486
506
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
487
507
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -498,7 +518,12 @@ var envSchema = zod.z.object({
|
|
|
498
518
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
499
519
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
500
520
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
501
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
521
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
522
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
523
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
524
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
525
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
526
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
502
527
|
});
|
|
503
528
|
|
|
504
529
|
// config/env.ts
|
|
@@ -512,24 +537,47 @@ if (!results.success) {
|
|
|
512
537
|
}
|
|
513
538
|
var config = results.data;
|
|
514
539
|
|
|
540
|
+
// config/pg-ssl.ts
|
|
541
|
+
function pgSslOptions() {
|
|
542
|
+
var _a;
|
|
543
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
544
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
545
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
546
|
+
}
|
|
547
|
+
|
|
515
548
|
// server/db/index.ts
|
|
516
549
|
var db;
|
|
517
550
|
if (config.DB_DRIVER === "pg") {
|
|
518
551
|
const pool = new pg.Pool({
|
|
519
552
|
connectionString: config.DATABASE_URL,
|
|
520
|
-
ssl: config.DATABASE_SSL ?
|
|
553
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
554
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
555
|
+
connectionTimeoutMillis: 5e3,
|
|
556
|
+
query_timeout: 15e3
|
|
557
|
+
// roomy enough for the 10k-row exports
|
|
521
558
|
});
|
|
522
559
|
db = nodePostgres.drizzle(pool, {
|
|
523
560
|
schema: schema_exports,
|
|
524
|
-
logger:
|
|
561
|
+
logger: process.env.NODE_ENV === "development"
|
|
525
562
|
});
|
|
526
563
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
527
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
528
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
529
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
530
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
531
564
|
} else {
|
|
532
|
-
|
|
565
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
566
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
567
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
568
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
572
|
+
function toBufferSource(data) {
|
|
573
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
574
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
575
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
576
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
577
|
+
}
|
|
578
|
+
function toUint8Array(data) {
|
|
579
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
580
|
+
return new Uint8Array(data);
|
|
533
581
|
}
|
|
534
582
|
|
|
535
583
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -538,9 +586,7 @@ function getAlphabet(hex2) {
|
|
|
538
586
|
}
|
|
539
587
|
function createDecodeMap(alphabet) {
|
|
540
588
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
541
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
542
|
-
decodeMap.set(alphabet[i], i);
|
|
543
|
-
}
|
|
589
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
544
590
|
return decodeMap;
|
|
545
591
|
}
|
|
546
592
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -555,9 +601,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
555
601
|
result += alphabet[buffer >> shift & 31];
|
|
556
602
|
}
|
|
557
603
|
}
|
|
558
|
-
if (shift > 0)
|
|
559
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
560
|
-
}
|
|
604
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
561
605
|
if (padding) {
|
|
562
606
|
const padCount = (8 - result.length % 8) % 8;
|
|
563
607
|
result += "=".repeat(padCount);
|
|
@@ -570,12 +614,9 @@ function base32Decode(data, alphabet) {
|
|
|
570
614
|
let buffer = 0;
|
|
571
615
|
let bitsCollected = 0;
|
|
572
616
|
for (const char of data) {
|
|
573
|
-
if (char === "=")
|
|
574
|
-
break;
|
|
617
|
+
if (char === "=") break;
|
|
575
618
|
const value = decodeMap.get(char);
|
|
576
|
-
if (value === void 0) {
|
|
577
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
578
|
-
}
|
|
619
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
579
620
|
buffer = buffer << 5 | value;
|
|
580
621
|
bitsCollected += 5;
|
|
581
622
|
while (bitsCollected >= 8) {
|
|
@@ -587,68 +628,34 @@ function base32Decode(data, alphabet) {
|
|
|
587
628
|
}
|
|
588
629
|
var base32 = {
|
|
589
630
|
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
631
|
+
* Encodes data into a Base32 string.
|
|
632
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
633
|
+
* @param options - Encoding options.
|
|
634
|
+
* @returns The Base32 encoded string.
|
|
635
|
+
*/
|
|
595
636
|
encode(data, options = {}) {
|
|
596
637
|
var _a;
|
|
597
638
|
const alphabet = getAlphabet();
|
|
598
|
-
|
|
599
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
639
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
600
640
|
},
|
|
601
641
|
/**
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
642
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
643
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
644
|
+
* @returns The decoded Uint8Array.
|
|
645
|
+
*/
|
|
606
646
|
decode(data) {
|
|
607
|
-
if (typeof data !== "string")
|
|
608
|
-
data = new TextDecoder().decode(data);
|
|
609
|
-
}
|
|
647
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
610
648
|
const alphabet = getAlphabet();
|
|
611
649
|
return base32Decode(data, alphabet);
|
|
612
650
|
}
|
|
613
651
|
};
|
|
614
652
|
|
|
615
|
-
// node_modules/@better-auth/utils/dist/
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
if (data.byteLength === 0) {
|
|
623
|
-
return "";
|
|
624
|
-
}
|
|
625
|
-
const buffer = new Uint8Array(data);
|
|
626
|
-
let result = "";
|
|
627
|
-
for (const byte of buffer) {
|
|
628
|
-
result += byte.toString(16).padStart(2, "0");
|
|
629
|
-
}
|
|
630
|
-
return result;
|
|
631
|
-
},
|
|
632
|
-
decode: (data) => {
|
|
633
|
-
if (!data) {
|
|
634
|
-
return "";
|
|
635
|
-
}
|
|
636
|
-
if (typeof data === "string") {
|
|
637
|
-
if (data.length % 2 !== 0) {
|
|
638
|
-
throw new Error("Invalid hexadecimal string");
|
|
639
|
-
}
|
|
640
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
641
|
-
throw new Error("Invalid hexadecimal string");
|
|
642
|
-
}
|
|
643
|
-
const result = new Uint8Array(data.length / 2);
|
|
644
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
645
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
646
|
-
}
|
|
647
|
-
return new TextDecoder().decode(result);
|
|
648
|
-
}
|
|
649
|
-
return new TextDecoder().decode(data);
|
|
650
|
-
}
|
|
651
|
-
};
|
|
653
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
654
|
+
function getWebcryptoSubtle() {
|
|
655
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
656
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
657
|
+
throw new Error("crypto.subtle must be defined");
|
|
658
|
+
}
|
|
652
659
|
|
|
653
660
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
654
661
|
function getAlphabet2(urlSafe) {
|
|
@@ -666,9 +673,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
666
673
|
result += alphabet[buffer >> shift & 63];
|
|
667
674
|
}
|
|
668
675
|
}
|
|
669
|
-
if (shift > 0)
|
|
670
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
671
|
-
}
|
|
676
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
672
677
|
if (padding) {
|
|
673
678
|
const padCount = (4 - result.length % 4) % 4;
|
|
674
679
|
result += "=".repeat(padCount);
|
|
@@ -677,19 +682,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
677
682
|
}
|
|
678
683
|
function base64Decode(data, alphabet) {
|
|
679
684
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
680
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
681
|
-
decodeMap.set(alphabet[i], i);
|
|
682
|
-
}
|
|
685
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
683
686
|
const result = [];
|
|
684
687
|
let buffer = 0;
|
|
685
688
|
let bitsCollected = 0;
|
|
686
689
|
for (const char of data) {
|
|
687
|
-
if (char === "=")
|
|
688
|
-
break;
|
|
690
|
+
if (char === "=") break;
|
|
689
691
|
const value = decodeMap.get(char);
|
|
690
|
-
if (value === void 0) {
|
|
691
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
692
|
-
}
|
|
692
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
693
693
|
buffer = buffer << 6 | value;
|
|
694
694
|
bitsCollected += 6;
|
|
695
695
|
if (bitsCollected >= 8) {
|
|
@@ -703,15 +703,11 @@ var base64 = {
|
|
|
703
703
|
encode(data, options = {}) {
|
|
704
704
|
var _a;
|
|
705
705
|
const alphabet = getAlphabet2(false);
|
|
706
|
-
|
|
707
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
706
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
708
707
|
},
|
|
709
708
|
decode(data) {
|
|
710
|
-
if (typeof data !== "string")
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
714
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
709
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
710
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
715
711
|
return base64Decode(data, alphabet);
|
|
716
712
|
}
|
|
717
713
|
};
|
|
@@ -719,152 +715,142 @@ var base64Url = {
|
|
|
719
715
|
encode(data, options = {}) {
|
|
720
716
|
var _a;
|
|
721
717
|
const alphabet = getAlphabet2(true);
|
|
722
|
-
|
|
723
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
718
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
724
719
|
},
|
|
725
720
|
decode(data) {
|
|
726
|
-
|
|
727
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
728
|
-
return base64Decode(data, alphabet);
|
|
721
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
729
722
|
}
|
|
730
723
|
};
|
|
731
724
|
|
|
732
|
-
// node_modules/@
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
725
|
+
// node_modules/@noble/hashes/utils.js
|
|
726
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
727
|
+
// @ts-ignore
|
|
728
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
729
|
+
))();
|
|
730
|
+
function asciiToBase16(ch) {
|
|
731
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
732
|
+
}
|
|
733
|
+
function hexToBytes(hex2) {
|
|
734
|
+
if (typeof hex2 !== "string")
|
|
735
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
736
|
+
if (hasHexBuiltin) {
|
|
737
|
+
try {
|
|
738
|
+
return Uint8Array.fromHex(hex2);
|
|
739
|
+
} catch (error) {
|
|
740
|
+
if (error instanceof SyntaxError)
|
|
741
|
+
throw new RangeError(error.message);
|
|
742
|
+
throw error;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const hl = hex2.length;
|
|
746
|
+
const al = hl / 2;
|
|
747
|
+
if (hl % 2)
|
|
748
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
749
|
+
const array = new Uint8Array(al);
|
|
750
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
751
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
752
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
753
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
754
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
755
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
756
|
+
}
|
|
757
|
+
array[ai] = n1 * 16 + n2;
|
|
758
|
+
}
|
|
759
|
+
return array;
|
|
738
760
|
}
|
|
739
761
|
|
|
762
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
763
|
+
var toBytes = (data) => hexToBytes(data);
|
|
764
|
+
var hex = {
|
|
765
|
+
encode: (data) => {
|
|
766
|
+
const buffer = toUint8Array(data);
|
|
767
|
+
if (buffer.byteLength === 0) return "";
|
|
768
|
+
let result = "";
|
|
769
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
770
|
+
return result;
|
|
771
|
+
},
|
|
772
|
+
decode: (data) => {
|
|
773
|
+
if (!data) return "";
|
|
774
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
775
|
+
return new TextDecoder().decode(data);
|
|
776
|
+
},
|
|
777
|
+
toBytes
|
|
778
|
+
};
|
|
779
|
+
|
|
740
780
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
741
781
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
742
|
-
const
|
|
782
|
+
const hmac2 = {
|
|
743
783
|
importKey: async (key, keyUsage) => {
|
|
744
|
-
return getWebcryptoSubtle().importKey(
|
|
745
|
-
"
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
false,
|
|
749
|
-
[keyUsage]
|
|
750
|
-
);
|
|
784
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
785
|
+
name: "HMAC",
|
|
786
|
+
hash: { name: algorithm }
|
|
787
|
+
}, false, [keyUsage]);
|
|
751
788
|
},
|
|
752
789
|
sign: async (hmacKey, data) => {
|
|
753
|
-
if (typeof hmacKey === "string")
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
hmacKey,
|
|
759
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
760
|
-
);
|
|
761
|
-
if (encoding === "hex") {
|
|
762
|
-
return hex.encode(signature);
|
|
763
|
-
}
|
|
764
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
765
|
-
return base64Url.encode(signature, {
|
|
766
|
-
padding: encoding !== "base64urlnopad"
|
|
767
|
-
});
|
|
768
|
-
}
|
|
790
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
791
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
792
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
793
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
794
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
769
795
|
return signature;
|
|
770
796
|
},
|
|
771
797
|
verify: async (hmacKey, data, signature) => {
|
|
772
|
-
if (typeof hmacKey === "string")
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
signature = hex.decode(signature);
|
|
777
|
-
}
|
|
778
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
779
|
-
signature = await base64.decode(signature);
|
|
780
|
-
}
|
|
781
|
-
return getWebcryptoSubtle().verify(
|
|
782
|
-
"HMAC",
|
|
783
|
-
hmacKey,
|
|
784
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
785
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
786
|
-
);
|
|
798
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
799
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
800
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
801
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
787
802
|
}
|
|
788
803
|
};
|
|
789
|
-
return
|
|
804
|
+
return hmac2;
|
|
790
805
|
};
|
|
791
806
|
|
|
792
807
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
793
808
|
var defaultPeriod = 30;
|
|
794
809
|
var defaultDigits = 6;
|
|
810
|
+
var hmac = createHMAC("SHA-1");
|
|
795
811
|
function constantTimeEqualOTP(input, expected) {
|
|
796
812
|
let difference = input.length ^ expected.length;
|
|
797
|
-
for (let i = 0; i < expected.length; i++)
|
|
798
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
799
|
-
}
|
|
813
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
800
814
|
return difference === 0;
|
|
801
815
|
}
|
|
802
|
-
async function generateHOTP(
|
|
803
|
-
counter,
|
|
804
|
-
digits,
|
|
805
|
-
hash = "SHA-1"
|
|
806
|
-
}) {
|
|
816
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
807
817
|
const _digits = digits != null ? digits : defaultDigits;
|
|
808
|
-
if (_digits < 1 || _digits > 8)
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
const buffer = new ArrayBuffer(8);
|
|
818
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
819
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
812
820
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
813
821
|
const bytes = new Uint8Array(buffer);
|
|
814
|
-
const
|
|
822
|
+
const signature = await hmac.sign(key, bytes);
|
|
823
|
+
const hmacResult = new Uint8Array(signature);
|
|
815
824
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
816
|
-
|
|
817
|
-
const otp = truncated % 10 ** _digits;
|
|
818
|
-
return otp.toString().padStart(_digits, "0");
|
|
825
|
+
return (((hmacResult[offset] & 127) << 24 | (hmacResult[offset + 1] & 255) << 16 | (hmacResult[offset + 2] & 255) << 8 | hmacResult[offset + 3] & 255) % 10 ** _digits).toString().padStart(_digits, "0");
|
|
819
826
|
}
|
|
820
|
-
async function generateTOTP(
|
|
827
|
+
async function generateTOTP(key, options) {
|
|
821
828
|
var _a, _b;
|
|
822
829
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
830
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
831
|
+
return await generateHOTP(key, {
|
|
832
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
833
|
+
digits
|
|
834
|
+
});
|
|
827
835
|
}
|
|
828
|
-
async function verifyTOTP(otp, {
|
|
829
|
-
window = 1,
|
|
830
|
-
digits = defaultDigits,
|
|
831
|
-
secret,
|
|
832
|
-
period = defaultPeriod
|
|
833
|
-
}) {
|
|
836
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
834
837
|
const milliseconds = period * 1e3;
|
|
835
838
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
836
839
|
let matched = false;
|
|
837
|
-
for (let i = -window; i <= window; i++) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
});
|
|
842
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
843
|
-
}
|
|
840
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
841
|
+
counter: counter + i,
|
|
842
|
+
digits
|
|
843
|
+
})) || matched;
|
|
844
844
|
return matched;
|
|
845
845
|
}
|
|
846
|
-
function generateQRCode({
|
|
847
|
-
issuer
|
|
848
|
-
account,
|
|
849
|
-
secret,
|
|
850
|
-
digits = defaultDigits,
|
|
851
|
-
period = defaultPeriod
|
|
852
|
-
}) {
|
|
853
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
854
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
855
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
846
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
847
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
856
848
|
const params = new URLSearchParams({
|
|
857
|
-
secret: base32.encode(secret, {
|
|
858
|
-
padding: false
|
|
859
|
-
}),
|
|
849
|
+
secret: base32.encode(secret, { padding: false }),
|
|
860
850
|
issuer
|
|
861
851
|
});
|
|
862
|
-
if (digits !== void 0)
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
if (period !== void 0) {
|
|
866
|
-
params.set("period", period.toString());
|
|
867
|
-
}
|
|
852
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
853
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
868
854
|
return `${baseURI}?${params.toString()}`;
|
|
869
855
|
}
|
|
870
856
|
var createOTP = (secret, opts) => {
|
|
@@ -872,10 +858,34 @@ var createOTP = (secret, opts) => {
|
|
|
872
858
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
873
859
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
874
860
|
return {
|
|
875
|
-
hotp: (counter) =>
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
861
|
+
hotp: async (counter) => {
|
|
862
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
863
|
+
counter,
|
|
864
|
+
digits
|
|
865
|
+
});
|
|
866
|
+
},
|
|
867
|
+
totp: async () => {
|
|
868
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
869
|
+
digits,
|
|
870
|
+
period
|
|
871
|
+
});
|
|
872
|
+
},
|
|
873
|
+
verify: async (otp, options) => {
|
|
874
|
+
return verifyTOTP(otp, __spreadValues({
|
|
875
|
+
key: await hmac.importKey(secret, "sign"),
|
|
876
|
+
digits,
|
|
877
|
+
period
|
|
878
|
+
}, options));
|
|
879
|
+
},
|
|
880
|
+
url: (issuer, account) => {
|
|
881
|
+
return generateQRCode({
|
|
882
|
+
issuer,
|
|
883
|
+
account,
|
|
884
|
+
secret,
|
|
885
|
+
digits,
|
|
886
|
+
period
|
|
887
|
+
});
|
|
888
|
+
}
|
|
879
889
|
};
|
|
880
890
|
};
|
|
881
891
|
|
|
@@ -952,6 +962,8 @@ async function logActivity({
|
|
|
952
962
|
try {
|
|
953
963
|
await db.insert(activityLogs).values({
|
|
954
964
|
userId,
|
|
965
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
966
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
955
967
|
action,
|
|
956
968
|
description,
|
|
957
969
|
ipAddress: ipAddress || null,
|
|
@@ -972,7 +984,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
972
984
|
function getClientIp(headers3) {
|
|
973
985
|
var _a;
|
|
974
986
|
const forwardedFor = headers3 == null ? void 0 : headers3.get("x-forwarded-for");
|
|
975
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
987
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
976
988
|
return (_a = headers3 == null ? void 0 : headers3.get("x-real-ip")) != null ? _a : null;
|
|
977
989
|
}
|
|
978
990
|
function parseUserAgent(userAgent) {
|
|
@@ -1015,6 +1027,16 @@ function formatLocation({ country, city }) {
|
|
|
1015
1027
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1016
1028
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1017
1029
|
|
|
1030
|
+
// lib/auth/base-url.ts
|
|
1031
|
+
function getBaseUrl() {
|
|
1032
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1033
|
+
return url.replace(/\/+$/, "");
|
|
1034
|
+
}
|
|
1035
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1036
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1037
|
+
return drizzleOrm.sql`(select count(*) from (select ${users.id} as id from ${users} where ${users.role} = 'admin' and ${users.banned} = false for update) a where a.id not in (${ids})) > 0`;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1018
1040
|
// lib/auth/throttle-limits.ts
|
|
1019
1041
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1020
1042
|
var MAX = 10;
|
|
@@ -1050,8 +1072,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1050
1072
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1051
1073
|
target: authThrottle.fingerprint,
|
|
1052
1074
|
set: __spreadValues({
|
|
1053
|
-
|
|
1054
|
-
|
|
1075
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1076
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1077
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1078
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1055
1079
|
}, seen)
|
|
1056
1080
|
});
|
|
1057
1081
|
} catch (error) {
|
|
@@ -1070,15 +1094,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1070
1094
|
console.error("auth-throttle prune failed", error);
|
|
1071
1095
|
}
|
|
1072
1096
|
}
|
|
1073
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1074
|
-
try {
|
|
1075
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1076
|
-
} catch (error) {
|
|
1077
|
-
console.error("auth-throttle clear failed", error);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
1097
|
var SETTINGS_ROW_ID = "default";
|
|
1081
1098
|
var CACHE_TTL_MS = 1e4;
|
|
1099
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1082
1100
|
var cached = null;
|
|
1083
1101
|
function fallbackSettings() {
|
|
1084
1102
|
return {
|
|
@@ -1121,7 +1139,9 @@ async function getSystemSettings() {
|
|
|
1121
1139
|
return value;
|
|
1122
1140
|
} catch (error) {
|
|
1123
1141
|
console.error("Failed to load system settings, failing open:", error);
|
|
1124
|
-
|
|
1142
|
+
const value = fallbackSettings();
|
|
1143
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1144
|
+
return value;
|
|
1125
1145
|
}
|
|
1126
1146
|
}
|
|
1127
1147
|
async function getEffectiveAuthFlags() {
|
|
@@ -1198,7 +1218,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1198
1218
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1199
1219
|
ipAddress: ip || "Unknown",
|
|
1200
1220
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1201
|
-
manageUrl: `${
|
|
1221
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1202
1222
|
})
|
|
1203
1223
|
});
|
|
1204
1224
|
} catch (error) {
|
|
@@ -1273,7 +1293,7 @@ function createAuth(overrides = {}) {
|
|
|
1273
1293
|
"No auth provider is enabled \u2014 every social provider is off and emailAndPassword.enabled is false. Enable AUTH_ENABLE_GOOGLE / AUTH_ENABLE_EMAIL_PASSWORD, or pass your own provider via createAuth({ socialProviders: {...} })."
|
|
1274
1294
|
);
|
|
1275
1295
|
}
|
|
1276
|
-
const baseURL =
|
|
1296
|
+
const baseURL = getBaseUrl();
|
|
1277
1297
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1278
1298
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1279
1299
|
issuer: config.APP_NAME,
|
|
@@ -1407,7 +1427,7 @@ function createAuth(overrides = {}) {
|
|
|
1407
1427
|
// available together.
|
|
1408
1428
|
hooks: {
|
|
1409
1429
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1410
|
-
var _a2, _b2, _c2, _d2;
|
|
1430
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1411
1431
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1412
1432
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1413
1433
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1441,6 +1461,9 @@ function createAuth(overrides = {}) {
|
|
|
1441
1461
|
}
|
|
1442
1462
|
return;
|
|
1443
1463
|
}
|
|
1464
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1465
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1466
|
+
}
|
|
1444
1467
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1445
1468
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1446
1469
|
}
|
|
@@ -1451,8 +1474,8 @@ function createAuth(overrides = {}) {
|
|
|
1451
1474
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1452
1475
|
}
|
|
1453
1476
|
if (current2.user.role === "admin") {
|
|
1454
|
-
const [
|
|
1455
|
-
if (
|
|
1477
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1478
|
+
if (!other) {
|
|
1456
1479
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1457
1480
|
}
|
|
1458
1481
|
}
|
|
@@ -1465,7 +1488,7 @@ function createAuth(overrides = {}) {
|
|
|
1465
1488
|
await log({
|
|
1466
1489
|
userId: current.session.impersonatedBy,
|
|
1467
1490
|
action: "impersonation_stopped",
|
|
1468
|
-
description: `Admin stopped impersonating ${(
|
|
1491
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1469
1492
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1470
1493
|
});
|
|
1471
1494
|
}
|
|
@@ -1501,8 +1524,6 @@ function createAuth(overrides = {}) {
|
|
|
1501
1524
|
if (failed) {
|
|
1502
1525
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1503
1526
|
await logFailedLogin(ctx, log);
|
|
1504
|
-
} else {
|
|
1505
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1506
1527
|
}
|
|
1507
1528
|
})
|
|
1508
1529
|
},
|
|
@@ -1583,9 +1604,20 @@ var auth = new Proxy({}, {
|
|
|
1583
1604
|
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
1584
1605
|
}
|
|
1585
1606
|
});
|
|
1607
|
+
|
|
1608
|
+
// lib/auth/pure.ts
|
|
1609
|
+
function hasRole(userRole, requiredRole) {
|
|
1610
|
+
if (!userRole) return false;
|
|
1611
|
+
{
|
|
1612
|
+
return userRole === "admin";
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// lib/auth/helpers.ts
|
|
1586
1617
|
var getCurrentSession = react.cache(async () => {
|
|
1587
1618
|
const session = await auth.api.getSession({
|
|
1588
|
-
headers: await headers.headers()
|
|
1619
|
+
headers: await headers.headers(),
|
|
1620
|
+
query: { disableCookieCache: true }
|
|
1589
1621
|
});
|
|
1590
1622
|
return session;
|
|
1591
1623
|
});
|
|
@@ -1604,11 +1636,11 @@ react.cache(async () => {
|
|
|
1604
1636
|
}
|
|
1605
1637
|
return __spreadProps(__spreadValues({}, session), { user: __spreadProps(__spreadValues({}, session.user), { role: (_c = (_b = user[0]) == null ? void 0 : _b.role) != null ? _c : session.user.role }) });
|
|
1606
1638
|
});
|
|
1607
|
-
function
|
|
1608
|
-
|
|
1609
|
-
{
|
|
1610
|
-
|
|
1611
|
-
|
|
1639
|
+
async function requireAdminApi() {
|
|
1640
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1641
|
+
if (!(session == null ? void 0 : session.user)) return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1642
|
+
if (!hasRole(session.user.role)) return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1643
|
+
return session;
|
|
1612
1644
|
}
|
|
1613
1645
|
var MARKETING_SEGMENT_ID = config.RESEND_MARKETING_SEGMENT_ID;
|
|
1614
1646
|
async function setSubscribed(email, name, subscribed) {
|
|
@@ -1683,18 +1715,9 @@ function unexpectedErrorMessage(error, message = "Something went wrong. Please t
|
|
|
1683
1715
|
}
|
|
1684
1716
|
|
|
1685
1717
|
// lib/marketing/route.ts
|
|
1686
|
-
async function getSession() {
|
|
1687
|
-
return auth.api.getSession({ headers: await headers.headers() });
|
|
1688
|
-
}
|
|
1689
1718
|
async function requireAdmin() {
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1692
|
-
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1693
|
-
}
|
|
1694
|
-
if (!hasRole(session.user.role)) {
|
|
1695
|
-
return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1696
|
-
}
|
|
1697
|
-
return null;
|
|
1719
|
+
const result = await requireAdminApi();
|
|
1720
|
+
return result instanceof server.NextResponse ? result : null;
|
|
1698
1721
|
}
|
|
1699
1722
|
var createSchema = zod.z.object({
|
|
1700
1723
|
segmentId: zod.z.string().min(1),
|
|
@@ -1793,7 +1816,7 @@ async function sendBroadcastPOST(_request, { params }) {
|
|
|
1793
1816
|
}
|
|
1794
1817
|
var subscriptionSchema = zod.z.object({ subscribed: zod.z.boolean() });
|
|
1795
1818
|
async function updateSubscriptionPUT(request) {
|
|
1796
|
-
const session = await getSession();
|
|
1819
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1797
1820
|
if (!(session == null ? void 0 : session.user)) {
|
|
1798
1821
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1799
1822
|
}
|