@factiii/auth 0.5.5 → 0.5.7

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.js CHANGED
@@ -42,7 +42,6 @@ __export(index_exports, {
42
42
  createAuthRouter: () => createAuthRouter,
43
43
  createAuthToken: () => createAuthToken,
44
44
  createConsoleEmailAdapter: () => createConsoleEmailAdapter,
45
- createDrizzleAdapter: () => createDrizzleAdapter,
46
45
  createNoopEmailAdapter: () => createNoopEmailAdapter,
47
46
  createOAuthVerifier: () => createOAuthVerifier,
48
47
  createPrismaAdapter: () => createPrismaAdapter,
@@ -390,298 +389,10 @@ function createConsoleEmailAdapter() {
390
389
  };
391
390
  }
392
391
 
393
- // src/adapters/drizzleAdapter.ts
394
- function createDrizzleAdapter(db, tables) {
395
- const {
396
- eq,
397
- and,
398
- or,
399
- isNull,
400
- isNotNull,
401
- gte,
402
- ne,
403
- sql
404
- } = require("drizzle-orm");
405
- const { users, sessions, otps, passwordResets, devices, admins } = tables;
406
- return {
407
- user: {
408
- async findByEmailInsensitive(email) {
409
- const rows = await db.select().from(users).where(sql`lower(${users.email}) = lower(${email})`).limit(1);
410
- return rows[0] ?? null;
411
- },
412
- async findByUsernameInsensitive(username) {
413
- const rows = await db.select().from(users).where(sql`lower(${users.username}) = lower(${username})`).limit(1);
414
- return rows[0] ?? null;
415
- },
416
- async findByEmailOrUsernameInsensitive(identifier) {
417
- const rows = await db.select().from(users).where(
418
- or(
419
- sql`lower(${users.email}) = lower(${identifier})`,
420
- sql`lower(${users.username}) = lower(${identifier})`
421
- )
422
- ).limit(1);
423
- return rows[0] ?? null;
424
- },
425
- async findByEmailOrOAuthId(email, oauthId) {
426
- const rows = await db.select().from(users).where(
427
- or(
428
- sql`lower(${users.email}) = lower(${email})`,
429
- eq(users.oauthId, oauthId)
430
- )
431
- ).limit(1);
432
- return rows[0] ?? null;
433
- },
434
- async findById(id) {
435
- const rows = await db.select().from(users).where(eq(users.id, id)).limit(1);
436
- return rows[0] ?? null;
437
- },
438
- async findActiveById(id) {
439
- const rows = await db.select().from(users).where(and(eq(users.id, id), eq(users.status, "ACTIVE"))).limit(1);
440
- return rows[0] ?? null;
441
- },
442
- async create(data) {
443
- const rows = await db.insert(users).values(data).returning();
444
- return rows[0];
445
- },
446
- async update(id, data) {
447
- const rows = await db.update(users).set(data).where(eq(users.id, id)).returning();
448
- return rows[0];
449
- }
450
- },
451
- session: {
452
- async findById(id) {
453
- const rows = await db.select({
454
- id: sessions.id,
455
- userId: sessions.userId,
456
- socketId: sessions.socketId,
457
- twoFaSecret: sessions.twoFaSecret,
458
- browserName: sessions.browserName,
459
- issuedAt: sessions.issuedAt,
460
- lastUsed: sessions.lastUsed,
461
- revokedAt: sessions.revokedAt,
462
- deviceId: sessions.deviceId,
463
- user: {
464
- status: users.status,
465
- verifiedHumanAt: users.verifiedHumanAt
466
- }
467
- }).from(sessions).innerJoin(users, eq(sessions.userId, users.id)).where(eq(sessions.id, id)).limit(1);
468
- return rows[0] ?? null;
469
- },
470
- async create(data) {
471
- const rows = await db.insert(sessions).values(data).returning();
472
- return rows[0];
473
- },
474
- async update(id, data) {
475
- const rows = await db.update(sessions).set(data).where(eq(sessions.id, id)).returning();
476
- return rows[0];
477
- },
478
- async updateLastUsed(id) {
479
- await db.update(sessions).set({ lastUsed: /* @__PURE__ */ new Date() }).where(eq(sessions.id, id));
480
- const rows = await db.select({
481
- id: sessions.id,
482
- userId: sessions.userId,
483
- socketId: sessions.socketId,
484
- twoFaSecret: sessions.twoFaSecret,
485
- browserName: sessions.browserName,
486
- issuedAt: sessions.issuedAt,
487
- lastUsed: sessions.lastUsed,
488
- revokedAt: sessions.revokedAt,
489
- deviceId: sessions.deviceId,
490
- user: {
491
- verifiedHumanAt: users.verifiedHumanAt
492
- }
493
- }).from(sessions).innerJoin(users, eq(sessions.userId, users.id)).where(eq(sessions.id, id)).limit(1);
494
- return rows[0];
495
- },
496
- async revoke(id) {
497
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(eq(sessions.id, id));
498
- },
499
- async findActiveByUserId(userId, excludeSessionId) {
500
- const conditions = [eq(sessions.userId, userId), isNull(sessions.revokedAt)];
501
- if (excludeSessionId !== void 0) {
502
- conditions.push(ne(sessions.id, excludeSessionId));
503
- }
504
- const activeRows = await db.select({
505
- id: sessions.id,
506
- socketId: sessions.socketId,
507
- userId: sessions.userId
508
- }).from(sessions).where(and(...conditions));
509
- return activeRows;
510
- },
511
- async revokeAllByUserId(userId, excludeSessionId) {
512
- const conditions = [eq(sessions.userId, userId), isNull(sessions.revokedAt)];
513
- if (excludeSessionId !== void 0) {
514
- conditions.push(ne(sessions.id, excludeSessionId));
515
- }
516
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(and(...conditions));
517
- },
518
- async findTwoFaSecretsByUserId(userId) {
519
- const secretRows = await db.select({ twoFaSecret: sessions.twoFaSecret }).from(sessions).where(and(eq(sessions.userId, userId), isNotNull(sessions.twoFaSecret)));
520
- return secretRows;
521
- },
522
- async clearTwoFaSecrets(userId, excludeSessionId) {
523
- const conditions = [eq(sessions.userId, userId)];
524
- if (excludeSessionId !== void 0) {
525
- conditions.push(ne(sessions.id, excludeSessionId));
526
- }
527
- await db.update(sessions).set({ twoFaSecret: null }).where(and(...conditions));
528
- },
529
- async findByIdWithDevice(id, userId) {
530
- const rows = await db.select({
531
- twoFaSecret: sessions.twoFaSecret,
532
- deviceId: sessions.deviceId,
533
- device: {
534
- pushToken: devices.pushToken
535
- }
536
- }).from(sessions).leftJoin(devices, eq(sessions.deviceId, devices.id)).where(and(eq(sessions.id, id), eq(sessions.userId, userId))).limit(1);
537
- if (!rows[0]) return null;
538
- const row = rows[0];
539
- const device = row.device;
540
- return {
541
- twoFaSecret: row.twoFaSecret,
542
- deviceId: row.deviceId,
543
- device: device?.pushToken ? { pushToken: device.pushToken } : null
544
- };
545
- },
546
- async revokeByDevicePushToken(userId, pushToken, excludeSessionId) {
547
- const deviceRows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
548
- if (!deviceRows[0]) return;
549
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(
550
- and(
551
- eq(sessions.userId, userId),
552
- ne(sessions.id, excludeSessionId),
553
- isNull(sessions.revokedAt),
554
- eq(sessions.deviceId, deviceRows[0].id)
555
- )
556
- );
557
- },
558
- async clearDeviceId(userId, deviceId) {
559
- await db.update(sessions).set({ deviceId: null }).where(and(eq(sessions.userId, userId), eq(sessions.deviceId, deviceId)));
560
- }
561
- },
562
- otp: {
563
- async findValidByUserAndCode(userId, code) {
564
- const rows = await db.select().from(otps).where(
565
- and(eq(otps.userId, userId), eq(otps.code, code), gte(otps.expiresAt, /* @__PURE__ */ new Date()))
566
- ).limit(1);
567
- return rows[0] ?? null;
568
- },
569
- async create(data) {
570
- const rows = await db.insert(otps).values(data).returning();
571
- return rows[0];
572
- },
573
- async delete(id) {
574
- await db.delete(otps).where(eq(otps.id, id));
575
- }
576
- },
577
- passwordReset: {
578
- async findById(id) {
579
- const rows = await db.select({
580
- id: passwordResets.id,
581
- createdAt: passwordResets.createdAt,
582
- userId: passwordResets.userId
583
- }).from(passwordResets).where(eq(passwordResets.id, id)).limit(1);
584
- return rows[0] ?? null;
585
- },
586
- async create(userId) {
587
- const rows = await db.insert(passwordResets).values({ userId }).returning();
588
- return rows[0];
589
- },
590
- async delete(id) {
591
- await db.delete(passwordResets).where(eq(passwordResets.id, id));
592
- },
593
- async deleteAllByUserId(userId) {
594
- await db.delete(passwordResets).where(eq(passwordResets.userId, userId));
595
- }
596
- },
597
- device: {
598
- async findByTokenSessionAndUser(pushToken, sessionId, userId) {
599
- const rows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
600
- if (!rows[0]) return null;
601
- if (tables.devicesToSessions && tables.devicesToUsers) {
602
- const sessionLink = await db.select().from(tables.devicesToSessions).where(
603
- and(
604
- eq(tables.devicesToSessions.deviceId, rows[0].id),
605
- eq(tables.devicesToSessions.sessionId, sessionId)
606
- )
607
- ).limit(1);
608
- const userLink = await db.select().from(tables.devicesToUsers).where(
609
- and(
610
- eq(tables.devicesToUsers.deviceId, rows[0].id),
611
- eq(tables.devicesToUsers.userId, userId)
612
- )
613
- ).limit(1);
614
- if (!sessionLink[0] || !userLink[0]) return null;
615
- }
616
- return { id: rows[0].id };
617
- },
618
- async upsertByPushToken(pushToken, sessionId, userId) {
619
- const existing = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
620
- let deviceId;
621
- if (existing[0]) {
622
- deviceId = existing[0].id;
623
- } else {
624
- const insertedRows = await db.insert(devices).values({ pushToken }).returning({ id: devices.id });
625
- deviceId = insertedRows[0].id;
626
- }
627
- if (tables.devicesToSessions) {
628
- await db.insert(tables.devicesToSessions).values({ deviceId, sessionId }).onConflictDoNothing();
629
- }
630
- if (tables.devicesToUsers) {
631
- await db.insert(tables.devicesToUsers).values({ deviceId, userId }).onConflictDoNothing();
632
- }
633
- await db.update(sessions).set({ deviceId }).where(eq(sessions.id, sessionId));
634
- },
635
- async findByUserAndToken(userId, pushToken) {
636
- if (tables.devicesToUsers) {
637
- const joinRows = await db.select({ id: devices.id }).from(devices).innerJoin(
638
- tables.devicesToUsers,
639
- eq(devices.id, tables.devicesToUsers.deviceId)
640
- ).where(
641
- and(
642
- eq(devices.pushToken, pushToken),
643
- eq(tables.devicesToUsers.userId, userId)
644
- )
645
- ).limit(1);
646
- return joinRows[0] ? { id: joinRows[0].id } : null;
647
- }
648
- const rows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
649
- return rows[0] ? { id: rows[0].id } : null;
650
- },
651
- async disconnectUser(deviceId, userId) {
652
- if (tables.devicesToUsers) {
653
- await db.delete(tables.devicesToUsers).where(
654
- and(
655
- eq(tables.devicesToUsers.deviceId, deviceId),
656
- eq(tables.devicesToUsers.userId, userId)
657
- )
658
- );
659
- }
660
- },
661
- async hasRemainingUsers(deviceId) {
662
- if (tables.devicesToUsers) {
663
- const remainingRows = await db.select({ userId: tables.devicesToUsers.userId }).from(tables.devicesToUsers).where(eq(tables.devicesToUsers.deviceId, deviceId)).limit(1);
664
- return remainingRows.length > 0;
665
- }
666
- return false;
667
- },
668
- async delete(id) {
669
- await db.delete(devices).where(eq(devices.id, id));
670
- }
671
- },
672
- admin: {
673
- async findByUserId(userId) {
674
- const rows = await db.select({ ip: admins.ip }).from(admins).where(eq(admins.userId, userId)).limit(1);
675
- return rows[0] ?? null;
676
- }
677
- }
678
- };
679
- }
680
-
681
392
  // src/utilities/config.ts
682
393
  var defaultTokenSettings = {
683
- jwtExpiry: 30 * 24 * 60 * 60,
684
- // 30 days in seconds
394
+ jwtExpiry: 365 * 24 * 60 * 60,
395
+ // 1 year in seconds
685
396
  passwordResetExpiryMs: 60 * 60 * 1e3,
686
397
  // 1 hour
687
398
  otpValidityMs: 15 * 60 * 1e3
@@ -692,8 +403,8 @@ var defaultCookieSettings = {
692
403
  sameSite: "Strict",
693
404
  httpOnly: false,
694
405
  path: "/",
695
- maxAge: 30 * 24 * 60 * 60
696
- // 30 days in seconds
406
+ maxAge: 365 * 24 * 60 * 60
407
+ // 1 year in seconds (matches jwtExpiry)
697
408
  };
698
409
  var defaultStorageKeys = {
699
410
  authToken: "auth-token"
@@ -2282,7 +1993,6 @@ function createAuthRouter(config) {
2282
1993
  createAuthRouter,
2283
1994
  createAuthToken,
2284
1995
  createConsoleEmailAdapter,
2285
- createDrizzleAdapter,
2286
1996
  createNoopEmailAdapter,
2287
1997
  createOAuthVerifier,
2288
1998
  createPrismaAdapter,
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- __require,
3
2
  biometricVerifySchema,
4
3
  changePasswordSchema,
5
4
  checkPasswordResetSchema,
@@ -18,7 +17,7 @@ import {
18
17
  twoFaResetVerifySchema,
19
18
  twoFaVerifySchema,
20
19
  verifyEmailSchema
21
- } from "./chunk-KUYH4DBN.mjs";
20
+ } from "./chunk-EHI4P63M.mjs";
22
21
 
23
22
  // src/middleware/authGuard.ts
24
23
  import { TRPCError } from "@trpc/server";
@@ -331,298 +330,10 @@ function createConsoleEmailAdapter() {
331
330
  };
332
331
  }
333
332
 
334
- // src/adapters/drizzleAdapter.ts
335
- function createDrizzleAdapter(db, tables) {
336
- const {
337
- eq,
338
- and,
339
- or,
340
- isNull,
341
- isNotNull,
342
- gte,
343
- ne,
344
- sql
345
- } = __require("drizzle-orm");
346
- const { users, sessions, otps, passwordResets, devices, admins } = tables;
347
- return {
348
- user: {
349
- async findByEmailInsensitive(email) {
350
- const rows = await db.select().from(users).where(sql`lower(${users.email}) = lower(${email})`).limit(1);
351
- return rows[0] ?? null;
352
- },
353
- async findByUsernameInsensitive(username) {
354
- const rows = await db.select().from(users).where(sql`lower(${users.username}) = lower(${username})`).limit(1);
355
- return rows[0] ?? null;
356
- },
357
- async findByEmailOrUsernameInsensitive(identifier) {
358
- const rows = await db.select().from(users).where(
359
- or(
360
- sql`lower(${users.email}) = lower(${identifier})`,
361
- sql`lower(${users.username}) = lower(${identifier})`
362
- )
363
- ).limit(1);
364
- return rows[0] ?? null;
365
- },
366
- async findByEmailOrOAuthId(email, oauthId) {
367
- const rows = await db.select().from(users).where(
368
- or(
369
- sql`lower(${users.email}) = lower(${email})`,
370
- eq(users.oauthId, oauthId)
371
- )
372
- ).limit(1);
373
- return rows[0] ?? null;
374
- },
375
- async findById(id) {
376
- const rows = await db.select().from(users).where(eq(users.id, id)).limit(1);
377
- return rows[0] ?? null;
378
- },
379
- async findActiveById(id) {
380
- const rows = await db.select().from(users).where(and(eq(users.id, id), eq(users.status, "ACTIVE"))).limit(1);
381
- return rows[0] ?? null;
382
- },
383
- async create(data) {
384
- const rows = await db.insert(users).values(data).returning();
385
- return rows[0];
386
- },
387
- async update(id, data) {
388
- const rows = await db.update(users).set(data).where(eq(users.id, id)).returning();
389
- return rows[0];
390
- }
391
- },
392
- session: {
393
- async findById(id) {
394
- const rows = await db.select({
395
- id: sessions.id,
396
- userId: sessions.userId,
397
- socketId: sessions.socketId,
398
- twoFaSecret: sessions.twoFaSecret,
399
- browserName: sessions.browserName,
400
- issuedAt: sessions.issuedAt,
401
- lastUsed: sessions.lastUsed,
402
- revokedAt: sessions.revokedAt,
403
- deviceId: sessions.deviceId,
404
- user: {
405
- status: users.status,
406
- verifiedHumanAt: users.verifiedHumanAt
407
- }
408
- }).from(sessions).innerJoin(users, eq(sessions.userId, users.id)).where(eq(sessions.id, id)).limit(1);
409
- return rows[0] ?? null;
410
- },
411
- async create(data) {
412
- const rows = await db.insert(sessions).values(data).returning();
413
- return rows[0];
414
- },
415
- async update(id, data) {
416
- const rows = await db.update(sessions).set(data).where(eq(sessions.id, id)).returning();
417
- return rows[0];
418
- },
419
- async updateLastUsed(id) {
420
- await db.update(sessions).set({ lastUsed: /* @__PURE__ */ new Date() }).where(eq(sessions.id, id));
421
- const rows = await db.select({
422
- id: sessions.id,
423
- userId: sessions.userId,
424
- socketId: sessions.socketId,
425
- twoFaSecret: sessions.twoFaSecret,
426
- browserName: sessions.browserName,
427
- issuedAt: sessions.issuedAt,
428
- lastUsed: sessions.lastUsed,
429
- revokedAt: sessions.revokedAt,
430
- deviceId: sessions.deviceId,
431
- user: {
432
- verifiedHumanAt: users.verifiedHumanAt
433
- }
434
- }).from(sessions).innerJoin(users, eq(sessions.userId, users.id)).where(eq(sessions.id, id)).limit(1);
435
- return rows[0];
436
- },
437
- async revoke(id) {
438
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(eq(sessions.id, id));
439
- },
440
- async findActiveByUserId(userId, excludeSessionId) {
441
- const conditions = [eq(sessions.userId, userId), isNull(sessions.revokedAt)];
442
- if (excludeSessionId !== void 0) {
443
- conditions.push(ne(sessions.id, excludeSessionId));
444
- }
445
- const activeRows = await db.select({
446
- id: sessions.id,
447
- socketId: sessions.socketId,
448
- userId: sessions.userId
449
- }).from(sessions).where(and(...conditions));
450
- return activeRows;
451
- },
452
- async revokeAllByUserId(userId, excludeSessionId) {
453
- const conditions = [eq(sessions.userId, userId), isNull(sessions.revokedAt)];
454
- if (excludeSessionId !== void 0) {
455
- conditions.push(ne(sessions.id, excludeSessionId));
456
- }
457
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(and(...conditions));
458
- },
459
- async findTwoFaSecretsByUserId(userId) {
460
- const secretRows = await db.select({ twoFaSecret: sessions.twoFaSecret }).from(sessions).where(and(eq(sessions.userId, userId), isNotNull(sessions.twoFaSecret)));
461
- return secretRows;
462
- },
463
- async clearTwoFaSecrets(userId, excludeSessionId) {
464
- const conditions = [eq(sessions.userId, userId)];
465
- if (excludeSessionId !== void 0) {
466
- conditions.push(ne(sessions.id, excludeSessionId));
467
- }
468
- await db.update(sessions).set({ twoFaSecret: null }).where(and(...conditions));
469
- },
470
- async findByIdWithDevice(id, userId) {
471
- const rows = await db.select({
472
- twoFaSecret: sessions.twoFaSecret,
473
- deviceId: sessions.deviceId,
474
- device: {
475
- pushToken: devices.pushToken
476
- }
477
- }).from(sessions).leftJoin(devices, eq(sessions.deviceId, devices.id)).where(and(eq(sessions.id, id), eq(sessions.userId, userId))).limit(1);
478
- if (!rows[0]) return null;
479
- const row = rows[0];
480
- const device = row.device;
481
- return {
482
- twoFaSecret: row.twoFaSecret,
483
- deviceId: row.deviceId,
484
- device: device?.pushToken ? { pushToken: device.pushToken } : null
485
- };
486
- },
487
- async revokeByDevicePushToken(userId, pushToken, excludeSessionId) {
488
- const deviceRows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
489
- if (!deviceRows[0]) return;
490
- await db.update(sessions).set({ revokedAt: /* @__PURE__ */ new Date() }).where(
491
- and(
492
- eq(sessions.userId, userId),
493
- ne(sessions.id, excludeSessionId),
494
- isNull(sessions.revokedAt),
495
- eq(sessions.deviceId, deviceRows[0].id)
496
- )
497
- );
498
- },
499
- async clearDeviceId(userId, deviceId) {
500
- await db.update(sessions).set({ deviceId: null }).where(and(eq(sessions.userId, userId), eq(sessions.deviceId, deviceId)));
501
- }
502
- },
503
- otp: {
504
- async findValidByUserAndCode(userId, code) {
505
- const rows = await db.select().from(otps).where(
506
- and(eq(otps.userId, userId), eq(otps.code, code), gte(otps.expiresAt, /* @__PURE__ */ new Date()))
507
- ).limit(1);
508
- return rows[0] ?? null;
509
- },
510
- async create(data) {
511
- const rows = await db.insert(otps).values(data).returning();
512
- return rows[0];
513
- },
514
- async delete(id) {
515
- await db.delete(otps).where(eq(otps.id, id));
516
- }
517
- },
518
- passwordReset: {
519
- async findById(id) {
520
- const rows = await db.select({
521
- id: passwordResets.id,
522
- createdAt: passwordResets.createdAt,
523
- userId: passwordResets.userId
524
- }).from(passwordResets).where(eq(passwordResets.id, id)).limit(1);
525
- return rows[0] ?? null;
526
- },
527
- async create(userId) {
528
- const rows = await db.insert(passwordResets).values({ userId }).returning();
529
- return rows[0];
530
- },
531
- async delete(id) {
532
- await db.delete(passwordResets).where(eq(passwordResets.id, id));
533
- },
534
- async deleteAllByUserId(userId) {
535
- await db.delete(passwordResets).where(eq(passwordResets.userId, userId));
536
- }
537
- },
538
- device: {
539
- async findByTokenSessionAndUser(pushToken, sessionId, userId) {
540
- const rows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
541
- if (!rows[0]) return null;
542
- if (tables.devicesToSessions && tables.devicesToUsers) {
543
- const sessionLink = await db.select().from(tables.devicesToSessions).where(
544
- and(
545
- eq(tables.devicesToSessions.deviceId, rows[0].id),
546
- eq(tables.devicesToSessions.sessionId, sessionId)
547
- )
548
- ).limit(1);
549
- const userLink = await db.select().from(tables.devicesToUsers).where(
550
- and(
551
- eq(tables.devicesToUsers.deviceId, rows[0].id),
552
- eq(tables.devicesToUsers.userId, userId)
553
- )
554
- ).limit(1);
555
- if (!sessionLink[0] || !userLink[0]) return null;
556
- }
557
- return { id: rows[0].id };
558
- },
559
- async upsertByPushToken(pushToken, sessionId, userId) {
560
- const existing = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
561
- let deviceId;
562
- if (existing[0]) {
563
- deviceId = existing[0].id;
564
- } else {
565
- const insertedRows = await db.insert(devices).values({ pushToken }).returning({ id: devices.id });
566
- deviceId = insertedRows[0].id;
567
- }
568
- if (tables.devicesToSessions) {
569
- await db.insert(tables.devicesToSessions).values({ deviceId, sessionId }).onConflictDoNothing();
570
- }
571
- if (tables.devicesToUsers) {
572
- await db.insert(tables.devicesToUsers).values({ deviceId, userId }).onConflictDoNothing();
573
- }
574
- await db.update(sessions).set({ deviceId }).where(eq(sessions.id, sessionId));
575
- },
576
- async findByUserAndToken(userId, pushToken) {
577
- if (tables.devicesToUsers) {
578
- const joinRows = await db.select({ id: devices.id }).from(devices).innerJoin(
579
- tables.devicesToUsers,
580
- eq(devices.id, tables.devicesToUsers.deviceId)
581
- ).where(
582
- and(
583
- eq(devices.pushToken, pushToken),
584
- eq(tables.devicesToUsers.userId, userId)
585
- )
586
- ).limit(1);
587
- return joinRows[0] ? { id: joinRows[0].id } : null;
588
- }
589
- const rows = await db.select({ id: devices.id }).from(devices).where(eq(devices.pushToken, pushToken)).limit(1);
590
- return rows[0] ? { id: rows[0].id } : null;
591
- },
592
- async disconnectUser(deviceId, userId) {
593
- if (tables.devicesToUsers) {
594
- await db.delete(tables.devicesToUsers).where(
595
- and(
596
- eq(tables.devicesToUsers.deviceId, deviceId),
597
- eq(tables.devicesToUsers.userId, userId)
598
- )
599
- );
600
- }
601
- },
602
- async hasRemainingUsers(deviceId) {
603
- if (tables.devicesToUsers) {
604
- const remainingRows = await db.select({ userId: tables.devicesToUsers.userId }).from(tables.devicesToUsers).where(eq(tables.devicesToUsers.deviceId, deviceId)).limit(1);
605
- return remainingRows.length > 0;
606
- }
607
- return false;
608
- },
609
- async delete(id) {
610
- await db.delete(devices).where(eq(devices.id, id));
611
- }
612
- },
613
- admin: {
614
- async findByUserId(userId) {
615
- const rows = await db.select({ ip: admins.ip }).from(admins).where(eq(admins.userId, userId)).limit(1);
616
- return rows[0] ?? null;
617
- }
618
- }
619
- };
620
- }
621
-
622
333
  // src/utilities/config.ts
623
334
  var defaultTokenSettings = {
624
- jwtExpiry: 30 * 24 * 60 * 60,
625
- // 30 days in seconds
335
+ jwtExpiry: 365 * 24 * 60 * 60,
336
+ // 1 year in seconds
626
337
  passwordResetExpiryMs: 60 * 60 * 1e3,
627
338
  // 1 hour
628
339
  otpValidityMs: 15 * 60 * 1e3
@@ -633,8 +344,8 @@ var defaultCookieSettings = {
633
344
  sameSite: "Strict",
634
345
  httpOnly: false,
635
346
  path: "/",
636
- maxAge: 30 * 24 * 60 * 60
637
- // 30 days in seconds
347
+ maxAge: 365 * 24 * 60 * 60
348
+ // 1 year in seconds (matches jwtExpiry)
638
349
  };
639
350
  var defaultStorageKeys = {
640
351
  authToken: "auth-token"
@@ -2144,7 +1855,6 @@ export {
2144
1855
  createAuthRouter,
2145
1856
  createAuthToken,
2146
1857
  createConsoleEmailAdapter,
2147
- createDrizzleAdapter,
2148
1858
  createNoopEmailAdapter,
2149
1859
  createOAuthVerifier,
2150
1860
  createPrismaAdapter,
@@ -1,2 +1,2 @@
1
1
  import 'zod';
2
- export { g as AuthSchemas, C as ChangePasswordInput, h as CreatedSchemas, L as LoginInput, i as LoginSchemaInput, O as OAuthLoginInput, j as OAuthSchemaInput, R as ResetPasswordInput, a as SignupInput, k as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, m as checkPasswordResetSchema, n as createSchemas, p as deregisterPushTokenSchema, q as disableTwofaSchema, e as endAllSessionsSchema, u as getTwofaSecretSchema, l as loginSchema, o as oAuthLoginSchema, w as registerPushTokenSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, x as twoFaResetVerifySchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-yHGJ7C6_.mjs';
2
+ export { g as AuthSchemas, C as ChangePasswordInput, h as CreatedSchemas, L as LoginInput, i as LoginSchemaInput, O as OAuthLoginInput, j as OAuthSchemaInput, R as ResetPasswordInput, a as SignupInput, k as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, m as checkPasswordResetSchema, n as createSchemas, p as deregisterPushTokenSchema, q as disableTwofaSchema, e as endAllSessionsSchema, u as getTwofaSecretSchema, l as loginSchema, o as oAuthLoginSchema, w as registerPushTokenSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, x as twoFaResetVerifySchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-BXNxNK4S.mjs';
@@ -1,2 +1,2 @@
1
1
  import 'zod';
2
- export { g as AuthSchemas, C as ChangePasswordInput, h as CreatedSchemas, L as LoginInput, i as LoginSchemaInput, O as OAuthLoginInput, j as OAuthSchemaInput, R as ResetPasswordInput, a as SignupInput, k as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, m as checkPasswordResetSchema, n as createSchemas, p as deregisterPushTokenSchema, q as disableTwofaSchema, e as endAllSessionsSchema, u as getTwofaSecretSchema, l as loginSchema, o as oAuthLoginSchema, w as registerPushTokenSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, x as twoFaResetVerifySchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-yHGJ7C6_.js';
2
+ export { g as AuthSchemas, C as ChangePasswordInput, h as CreatedSchemas, L as LoginInput, i as LoginSchemaInput, O as OAuthLoginInput, j as OAuthSchemaInput, R as ResetPasswordInput, a as SignupInput, k as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, m as checkPasswordResetSchema, n as createSchemas, p as deregisterPushTokenSchema, q as disableTwofaSchema, e as endAllSessionsSchema, u as getTwofaSecretSchema, l as loginSchema, o as oAuthLoginSchema, w as registerPushTokenSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, x as twoFaResetVerifySchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-BXNxNK4S.js';
@@ -17,7 +17,7 @@ import {
17
17
  twoFaResetVerifySchema,
18
18
  twoFaVerifySchema,
19
19
  verifyEmailSchema
20
- } from "./chunk-KUYH4DBN.mjs";
20
+ } from "./chunk-EHI4P63M.mjs";
21
21
  export {
22
22
  biometricVerifySchema,
23
23
  changePasswordSchema,