@factiii/auth 0.3.0 → 0.4.1

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.mjs CHANGED
@@ -8,20 +8,16 @@ import {
8
8
  endAllSessionsSchema,
9
9
  getTwofaSecretSchema,
10
10
  loginSchema,
11
- logoutSchema,
12
11
  oAuthLoginSchema,
13
- otpLoginRequestSchema,
14
- otpLoginVerifySchema,
15
12
  registerPushTokenSchema,
16
13
  requestPasswordResetSchema,
17
14
  resetPasswordSchema,
18
15
  signupSchema,
19
16
  twoFaResetSchema,
20
17
  twoFaResetVerifySchema,
21
- twoFaSetupSchema,
22
18
  twoFaVerifySchema,
23
19
  verifyEmailSchema
24
- } from "./chunk-PYVDWODF.mjs";
20
+ } from "./chunk-EHI4P63M.mjs";
25
21
 
26
22
  // src/middleware/authGuard.ts
27
23
  import { TRPCError } from "@trpc/server";
@@ -81,7 +77,8 @@ function createConsoleEmailAdapter() {
81
77
 
82
78
  // src/utilities/config.ts
83
79
  var defaultTokenSettings = {
84
- accessTokenExpiry: "5m",
80
+ jwtExpiry: 30 * 24 * 60 * 60,
81
+ // 30 days in seconds
85
82
  passwordResetExpiryMs: 60 * 60 * 1e3,
86
83
  // 1 hour
87
84
  otpValidityMs: 15 * 60 * 1e3
@@ -90,15 +87,13 @@ var defaultTokenSettings = {
90
87
  var defaultCookieSettings = {
91
88
  secure: true,
92
89
  sameSite: "Strict",
93
- httpOnly: true,
94
- accessTokenPath: "/",
95
- refreshTokenPath: "/api/trpc/auth.refresh",
96
- maxAge: 365 * 24 * 60 * 60
97
- // 1 year in seconds
90
+ httpOnly: false,
91
+ path: "/",
92
+ maxAge: 30 * 24 * 60 * 60
93
+ // 30 days in seconds
98
94
  };
99
95
  var defaultStorageKeys = {
100
- accessToken: "auth-at",
101
- refreshToken: "auth-rt"
96
+ authToken: "auth-token"
102
97
  };
103
98
  var defaultFeatures = {
104
99
  twoFa: true,
@@ -130,21 +125,17 @@ var defaultAuthConfig = {
130
125
 
131
126
  // src/utilities/cookies.ts
132
127
  var DEFAULT_STORAGE_KEYS = {
133
- ACCESS_TOKEN: "auth-at",
134
- REFRESH_TOKEN: "auth-rt"
128
+ AUTH_TOKEN: "auth-token"
135
129
  };
136
- function parseAuthCookies(cookieHeader, storageKeys = {
137
- accessToken: DEFAULT_STORAGE_KEYS.ACCESS_TOKEN,
138
- refreshToken: DEFAULT_STORAGE_KEYS.REFRESH_TOKEN
130
+ function parseAuthCookie(cookieHeader, storageKeys = {
131
+ authToken: DEFAULT_STORAGE_KEYS.AUTH_TOKEN
139
132
  }) {
140
133
  if (!cookieHeader) {
141
134
  return {};
142
135
  }
143
- const accessToken = cookieHeader.split(`${storageKeys.accessToken}=`)[1]?.split(";")[0];
144
- const refreshToken = cookieHeader.split(`${storageKeys.refreshToken}=`)[1]?.split(";")[0];
136
+ const authToken = cookieHeader.split(`${storageKeys.authToken}=`)[1]?.split(";")[0];
145
137
  return {
146
- accessToken: accessToken || void 0,
147
- refreshToken: refreshToken || void 0
138
+ authToken: authToken || void 0
148
139
  };
149
140
  }
150
141
  function extractDomain(req) {
@@ -168,76 +159,47 @@ function extractDomain(req) {
168
159
  }
169
160
  return void 0;
170
161
  }
171
- function setAuthCookies(res, credentials, settings, storageKeys = {
172
- accessToken: DEFAULT_STORAGE_KEYS.ACCESS_TOKEN,
173
- refreshToken: DEFAULT_STORAGE_KEYS.REFRESH_TOKEN
162
+ function setAuthCookie(res, authToken, settings, storageKeys = {
163
+ authToken: DEFAULT_STORAGE_KEYS.AUTH_TOKEN
174
164
  }) {
175
- const cookies = [];
176
165
  const domain = settings.domain ?? extractDomain(res.req);
177
166
  const expiresDate = settings.maxAge ? new Date(Date.now() + settings.maxAge * 1e3).toUTCString() : void 0;
178
- if (credentials.refreshToken) {
179
- const refreshCookie = [
180
- `${storageKeys.refreshToken}=${credentials.refreshToken}`,
181
- "HttpOnly",
182
- settings.secure ? "Secure=true" : "",
183
- `SameSite=${settings.sameSite}`,
184
- `Path=${settings.refreshTokenPath}`,
185
- domain ? `Domain=${domain}` : "",
186
- `Expires=${expiresDate}`
187
- ].filter(Boolean).join("; ");
188
- cookies.push(refreshCookie);
189
- }
190
- if (credentials.accessToken) {
191
- const accessCookie = [
192
- `${storageKeys.accessToken}=${credentials.accessToken}`,
193
- settings.secure ? "Secure=true" : "",
194
- `SameSite=${settings.sameSite}`,
195
- `Path=${settings.accessTokenPath}`,
196
- domain ? `Domain=${domain}` : "",
197
- `Expires=${expiresDate}`
198
- ].filter(Boolean).join("; ");
199
- cookies.push(accessCookie);
200
- }
201
- if (cookies.length > 0) {
202
- res.setHeader("Set-Cookie", cookies);
203
- }
167
+ const cookie = [
168
+ `${storageKeys.authToken}=${authToken}`,
169
+ settings.httpOnly ? "HttpOnly" : "",
170
+ settings.secure ? "Secure=true" : "",
171
+ `SameSite=${settings.sameSite}`,
172
+ `Path=${settings.path ?? "/"}`,
173
+ domain ? `Domain=${domain}` : "",
174
+ expiresDate ? `Expires=${expiresDate}` : ""
175
+ ].filter(Boolean).join("; ");
176
+ res.setHeader("Set-Cookie", cookie);
204
177
  }
205
- function clearAuthCookies(res, settings, storageKeys = {
206
- accessToken: DEFAULT_STORAGE_KEYS.ACCESS_TOKEN,
207
- refreshToken: DEFAULT_STORAGE_KEYS.REFRESH_TOKEN
178
+ function clearAuthCookie(res, settings, storageKeys = {
179
+ authToken: DEFAULT_STORAGE_KEYS.AUTH_TOKEN
208
180
  }) {
209
181
  const domain = extractDomain(res.req);
210
182
  const expiredDate = (/* @__PURE__ */ new Date(0)).toUTCString();
211
- const cookies = [
212
- [
213
- `${storageKeys.refreshToken}=destroy`,
214
- "HttpOnly",
215
- settings.secure ? "Secure=true" : "",
216
- `SameSite=${settings.sameSite}`,
217
- `Path=${settings.refreshTokenPath}`,
218
- domain ? `Domain=${domain}` : "",
219
- `Expires=${expiredDate}`
220
- ].filter(Boolean).join("; "),
221
- [
222
- `${storageKeys.accessToken}=destroy`,
223
- settings.secure ? "Secure=true" : "",
224
- `SameSite=${settings.sameSite}`,
225
- `Path=${settings.accessTokenPath}`,
226
- domain ? `Domain=${domain}` : "",
227
- `Expires=${expiredDate}`
228
- ].filter(Boolean).join("; ")
229
- ];
230
- res.setHeader("Set-Cookie", cookies);
183
+ const cookie = [
184
+ `${storageKeys.authToken}=destroy`,
185
+ settings.httpOnly ? "HttpOnly" : "",
186
+ settings.secure ? "Secure=true" : "",
187
+ `SameSite=${settings.sameSite}`,
188
+ `Path=${settings.path ?? "/"}`,
189
+ domain ? `Domain=${domain}` : "",
190
+ `Expires=${expiredDate}`
191
+ ].filter(Boolean).join("; ");
192
+ res.setHeader("Set-Cookie", cookie);
231
193
  }
232
194
 
233
195
  // src/utilities/jwt.ts
234
196
  import jwt from "jsonwebtoken";
235
- function createAccessToken(payload, options) {
197
+ function createAuthToken(payload, options) {
236
198
  return jwt.sign(payload, options.secret, {
237
199
  expiresIn: options.expiresIn
238
200
  });
239
201
  }
240
- function verifyAccessToken(token, options) {
202
+ function verifyAuthToken(token, options) {
241
203
  return jwt.verify(token, options.secret, {
242
204
  ignoreExpiration: options.ignoreExpiration ?? false
243
205
  });
@@ -264,7 +226,7 @@ function createAuthGuard(config, t) {
264
226
  const storageKeys = config.storageKeys ?? defaultStorageKeys;
265
227
  const cookieSettings = { ...defaultCookieSettings, ...config.cookieSettings };
266
228
  const revokeSession = async (ctx, sessionId, description, errorStack, path) => {
267
- clearAuthCookies(ctx.res, cookieSettings, storageKeys);
229
+ clearAuthCookie(ctx.res, cookieSettings, storageKeys);
268
230
  if (config.hooks?.logError) {
269
231
  try {
270
232
  const cookieHeader = ctx.headers.cookie;
@@ -275,7 +237,6 @@ function createAuthGuard(config, t) {
275
237
  ip: ctx.ip,
276
238
  userAgent: ctx.headers["user-agent"],
277
239
  ...path ? { path } : {},
278
- // Diagnostic: was Cookie header present at all, and which keys were sent?
279
240
  hasCookieHeader: Boolean(cookieHeader),
280
241
  cookieKeys: cookieHeader ? cookieHeader.split(";").map((c) => c.trim().split("=")[0]).filter(Boolean) : [],
281
242
  origin: ctx.headers.origin ?? null,
@@ -318,9 +279,8 @@ ${errorStack}` : null,
318
279
  }
319
280
  };
320
281
  const authGuard = t.middleware(async ({ ctx, meta, next, path }) => {
321
- const cookies = parseAuthCookies(ctx.headers.cookie, storageKeys);
322
- const authToken = cookies.accessToken;
323
- const refreshToken = cookies.refreshToken;
282
+ const cookies = parseAuthCookie(ctx.headers.cookie, storageKeys);
283
+ const authToken = cookies.authToken;
324
284
  const userAgent = ctx.headers["user-agent"];
325
285
  if (!userAgent) {
326
286
  throw new TRPCError({
@@ -330,27 +290,13 @@ ${errorStack}` : null,
330
290
  }
331
291
  if (authToken) {
332
292
  try {
333
- const decodedToken = verifyAccessToken(authToken, {
293
+ const decodedToken = verifyAuthToken(authToken, {
334
294
  secret: config.secrets.jwt,
335
295
  ignoreExpiration: meta?.ignoreExpiration ?? false
336
296
  });
337
- if (path === "auth.refresh" && !refreshToken) {
338
- await revokeSession(
339
- ctx,
340
- decodedToken.id,
341
- "Session revoked: No refresh token",
342
- void 0,
343
- path
344
- );
345
- throw new TRPCError({
346
- message: "Unauthorized",
347
- code: "UNAUTHORIZED"
348
- });
349
- }
350
297
  const session = await config.prisma.session.findUnique({
351
298
  where: {
352
- id: decodedToken.id,
353
- ...path === "auth.refresh" ? { refreshToken } : {}
299
+ id: decodedToken.id
354
300
  },
355
301
  select: {
356
302
  userId: true,
@@ -441,8 +387,7 @@ ${errorStack}` : null,
441
387
  ...ctx,
442
388
  userId: session.userId,
443
389
  socketId: session.socketId,
444
- sessionId: session.id,
445
- refreshToken
390
+ sessionId: session.id
446
391
  }
447
392
  });
448
393
  } catch (err) {
@@ -487,7 +432,6 @@ ${errorStack}` : null,
487
432
  }
488
433
 
489
434
  // src/procedures/base.ts
490
- import { randomUUID } from "crypto";
491
435
  import { TRPCError as TRPCError2 } from "@trpc/server";
492
436
 
493
437
  // src/utilities/browser.ts
@@ -713,31 +657,29 @@ var BaseProcedureFactory = class {
713
657
  if (this.config.hooks?.onUserCreated) {
714
658
  await this.config.hooks.onUserCreated(user.id, typedInput);
715
659
  }
716
- const refreshToken = randomUUID();
717
660
  const extraSessionData = this.config.hooks?.getSessionData ? await this.config.hooks.getSessionData(typedInput) : {};
718
661
  const session = await this.config.prisma.session.create({
719
662
  data: {
720
663
  userId: user.id,
721
664
  browserName: detectBrowser(userAgent),
722
665
  socketId: null,
723
- refreshToken,
724
666
  ...extraSessionData
725
667
  },
726
- select: { id: true, refreshToken: true, userId: true }
668
+ select: { id: true, userId: true }
727
669
  });
728
670
  if (this.config.hooks?.onSessionCreated) {
729
671
  await this.config.hooks.onSessionCreated(session.id, typedInput);
730
672
  }
731
- const accessToken = createAccessToken(
673
+ const authToken = createAuthToken(
732
674
  { id: session.id, userId: session.userId, verifiedHumanAt: null },
733
675
  {
734
676
  secret: this.config.secrets.jwt,
735
- expiresIn: this.config.tokenSettings.accessTokenExpiry
677
+ expiresIn: this.config.tokenSettings.jwtExpiry
736
678
  }
737
679
  );
738
- setAuthCookies(
680
+ setAuthCookie(
739
681
  ctx.res,
740
- { accessToken, refreshToken: session.refreshToken },
682
+ authToken,
741
683
  this.config.cookieSettings,
742
684
  this.config.storageKeys
743
685
  );
@@ -812,10 +754,10 @@ var BaseProcedureFactory = class {
812
754
  }
813
755
  if (user.twoFaEnabled && this.config.features?.twoFa) {
814
756
  if (!code) {
815
- throw new TRPCError2({
816
- code: "FORBIDDEN",
817
- message: "2FA code required."
818
- });
757
+ return {
758
+ success: false,
759
+ requires2FA: true
760
+ };
819
761
  }
820
762
  let validCode = false;
821
763
  const secrets = await this.config.prisma.session.findMany({
@@ -829,19 +771,13 @@ var BaseProcedureFactory = class {
829
771
  }
830
772
  }
831
773
  if (!validCode) {
832
- const checkOTP = await this.config.prisma.oTPBasedLogin.findFirst({
833
- where: {
834
- code: Number(code),
835
- userId: user.id,
836
- disabled: false,
837
- createdAt: { gte: new Date(Date.now() - this.config.tokenSettings.otpValidityMs) }
838
- }
774
+ const checkOTP = await this.config.prisma.oTP.findUnique({
775
+ where: { userId: user.id }
839
776
  });
840
- if (checkOTP) {
777
+ if (checkOTP && checkOTP.code === Number(code) && checkOTP.expiredAt >= /* @__PURE__ */ new Date()) {
841
778
  validCode = true;
842
- await this.config.prisma.oTPBasedLogin.updateMany({
843
- where: { code: Number(code) },
844
- data: { disabled: true }
779
+ await this.config.prisma.oTP.delete({
780
+ where: { userId: user.id }
845
781
  });
846
782
  }
847
783
  }
@@ -852,19 +788,16 @@ var BaseProcedureFactory = class {
852
788
  });
853
789
  }
854
790
  }
855
- const refreshToken = randomUUID();
856
791
  const extraSessionData = this.config.hooks?.getSessionData ? await this.config.hooks.getSessionData(typedInput) : {};
857
792
  const session = await this.config.prisma.session.create({
858
793
  data: {
859
794
  userId: user.id,
860
795
  browserName: detectBrowser(userAgent),
861
796
  socketId: null,
862
- refreshToken,
863
797
  ...extraSessionData
864
798
  },
865
799
  select: {
866
800
  id: true,
867
- refreshToken: true,
868
801
  userId: true,
869
802
  socketId: true,
870
803
  browserName: true,
@@ -881,16 +814,16 @@ var BaseProcedureFactory = class {
881
814
  if (this.config.hooks?.onSessionCreated) {
882
815
  await this.config.hooks.onSessionCreated(session.id, typedInput);
883
816
  }
884
- const accessToken = createAccessToken(
817
+ const authToken = createAuthToken(
885
818
  { id: session.id, userId: session.userId, verifiedHumanAt: user.verifiedHumanAt },
886
819
  {
887
820
  secret: this.config.secrets.jwt,
888
- expiresIn: this.config.tokenSettings.accessTokenExpiry
821
+ expiresIn: this.config.tokenSettings.jwtExpiry
889
822
  }
890
823
  );
891
- setAuthCookies(
824
+ setAuthCookie(
892
825
  ctx.res,
893
- { accessToken, refreshToken: session.refreshToken },
826
+ authToken,
894
827
  this.config.cookieSettings,
895
828
  this.config.storageKeys
896
829
  );
@@ -901,7 +834,7 @@ var BaseProcedureFactory = class {
901
834
  });
902
835
  }
903
836
  logout() {
904
- return this.procedure.mutation(async ({ ctx }) => {
837
+ return this.authProcedure.meta({ ignoreExpiration: true }).mutation(async ({ ctx }) => {
905
838
  const { userId, sessionId } = ctx;
906
839
  if (sessionId) {
907
840
  await this.config.prisma.session.update({
@@ -918,18 +851,17 @@ var BaseProcedureFactory = class {
918
851
  await this.config.hooks.afterLogout(userId, sessionId, ctx.socketId);
919
852
  }
920
853
  }
921
- clearAuthCookies(ctx.res, this.config.cookieSettings, this.config.storageKeys);
854
+ clearAuthCookie(ctx.res, this.config.cookieSettings, this.config.storageKeys);
922
855
  return { success: true };
923
856
  });
924
857
  }
925
858
  refresh() {
926
- return this.authProcedure.meta({ ignoreExpiration: true }).query(async ({ ctx }) => {
859
+ return this.authProcedure.query(async ({ ctx }) => {
927
860
  const session = await this.config.prisma.session.update({
928
861
  where: { id: ctx.sessionId },
929
- data: { refreshToken: randomUUID(), lastUsed: /* @__PURE__ */ new Date() },
862
+ data: { lastUsed: /* @__PURE__ */ new Date() },
930
863
  select: {
931
864
  id: true,
932
- refreshToken: true,
933
865
  userId: true,
934
866
  user: { select: { verifiedHumanAt: true } }
935
867
  }
@@ -938,16 +870,16 @@ var BaseProcedureFactory = class {
938
870
  this.config.hooks.onRefresh(session.userId).catch(() => {
939
871
  });
940
872
  }
941
- const accessToken = createAccessToken(
873
+ const authToken = createAuthToken(
942
874
  { id: session.id, userId: session.userId, verifiedHumanAt: session.user.verifiedHumanAt },
943
875
  {
944
876
  secret: this.config.secrets.jwt,
945
- expiresIn: this.config.tokenSettings.accessTokenExpiry
877
+ expiresIn: this.config.tokenSettings.jwtExpiry
946
878
  }
947
879
  );
948
- setAuthCookies(
880
+ setAuthCookie(
949
881
  ctx.res,
950
- { accessToken, refreshToken: session.refreshToken },
882
+ authToken,
951
883
  this.config.cookieSettings,
952
884
  this.config.storageKeys
953
885
  );
@@ -1175,7 +1107,7 @@ var BiometricProcedureFactory = class {
1175
1107
  };
1176
1108
 
1177
1109
  // src/procedures/emailVerification.ts
1178
- import { randomUUID as randomUUID2 } from "crypto";
1110
+ import { randomUUID } from "crypto";
1179
1111
  import { TRPCError as TRPCError4 } from "@trpc/server";
1180
1112
  var EmailVerificationProcedureFactory = class {
1181
1113
  constructor(config, authProcedure) {
@@ -1208,7 +1140,7 @@ var EmailVerificationProcedureFactory = class {
1208
1140
  if (user.emailVerificationStatus === "VERIFIED") {
1209
1141
  return { message: "Email is already verified", emailSent: false };
1210
1142
  }
1211
- const otp = randomUUID2();
1143
+ const otp = randomUUID();
1212
1144
  await this.config.prisma.user.update({
1213
1145
  where: { id: userId },
1214
1146
  data: { emailVerificationStatus: "PENDING", otpForEmailVerification: otp }
@@ -1273,7 +1205,6 @@ var EmailVerificationProcedureFactory = class {
1273
1205
  };
1274
1206
 
1275
1207
  // src/procedures/oauth.ts
1276
- import { randomUUID as randomUUID3 } from "crypto";
1277
1208
  import { TRPCError as TRPCError5 } from "@trpc/server";
1278
1209
  var OAuthLoginProcedureFactory = class {
1279
1210
  constructor(config, procedure) {
@@ -1372,19 +1303,16 @@ var OAuthLoginProcedureFactory = class {
1372
1303
  if (user.status === "BANNED") {
1373
1304
  throw new TRPCError5({ code: "FORBIDDEN", message: "Your account has been banned." });
1374
1305
  }
1375
- const refreshToken = randomUUID3();
1376
1306
  const extraSessionData = this.config.hooks?.getSessionData ? await this.config.hooks.getSessionData(typedInput) : {};
1377
1307
  const session = await this.config.prisma.session.create({
1378
1308
  data: {
1379
1309
  userId: user.id,
1380
1310
  browserName: detectBrowser(userAgent),
1381
1311
  socketId: null,
1382
- refreshToken,
1383
1312
  ...extraSessionData
1384
1313
  },
1385
1314
  select: {
1386
1315
  id: true,
1387
- refreshToken: true,
1388
1316
  userId: true,
1389
1317
  socketId: true,
1390
1318
  browserName: true,
@@ -1401,16 +1329,16 @@ var OAuthLoginProcedureFactory = class {
1401
1329
  if (this.config.hooks?.onSessionCreated) {
1402
1330
  await this.config.hooks.onSessionCreated(session.id, typedInput);
1403
1331
  }
1404
- const accessToken = createAccessToken(
1332
+ const authToken = createAuthToken(
1405
1333
  { id: session.id, userId: session.userId, verifiedHumanAt: user.verifiedHumanAt ?? null },
1406
1334
  {
1407
1335
  secret: this.config.secrets.jwt,
1408
- expiresIn: this.config.tokenSettings.accessTokenExpiry
1336
+ expiresIn: this.config.tokenSettings.jwtExpiry
1409
1337
  }
1410
1338
  );
1411
- setAuthCookies(
1339
+ setAuthCookie(
1412
1340
  ctx.res,
1413
- { accessToken, refreshToken: session.refreshToken },
1341
+ authToken,
1414
1342
  this.config.cookieSettings,
1415
1343
  this.config.storageKeys
1416
1344
  );
@@ -1608,8 +1536,11 @@ var TwoFaProcedureFactory = class {
1608
1536
  throw new TRPCError6({ code: "FORBIDDEN", message: "Invalid credentials." });
1609
1537
  }
1610
1538
  const otp = generateOtp();
1611
- await this.config.prisma.oTPBasedLogin.create({
1612
- data: { userId: user.id, code: otp }
1539
+ const expiredAt = new Date(Date.now() + this.config.tokenSettings.otpValidityMs);
1540
+ await this.config.prisma.oTP.upsert({
1541
+ where: { userId: user.id },
1542
+ update: { code: otp, expiredAt },
1543
+ create: { userId: user.id, code: otp, expiredAt }
1613
1544
  });
1614
1545
  if (this.config.emailService) {
1615
1546
  await this.config.emailService.sendOTPEmail(user.email, otp);
@@ -1628,20 +1559,14 @@ var TwoFaProcedureFactory = class {
1628
1559
  if (!user) {
1629
1560
  throw new TRPCError6({ code: "NOT_FOUND", message: "User not found" });
1630
1561
  }
1631
- const otp = await this.config.prisma.oTPBasedLogin.findFirst({
1632
- where: {
1633
- userId: user.id,
1634
- code,
1635
- disabled: false,
1636
- createdAt: { gte: new Date(Date.now() - this.config.tokenSettings.otpValidityMs) }
1637
- }
1562
+ const otp = await this.config.prisma.oTP.findUnique({
1563
+ where: { userId: user.id }
1638
1564
  });
1639
- if (!otp) {
1565
+ if (!otp || otp.code !== code || otp.expiredAt < /* @__PURE__ */ new Date()) {
1640
1566
  throw new TRPCError6({ code: "FORBIDDEN", message: "Invalid or expired OTP" });
1641
1567
  }
1642
- await this.config.prisma.oTPBasedLogin.update({
1643
- where: { id: otp.id },
1644
- data: { disabled: true }
1568
+ await this.config.prisma.oTP.delete({
1569
+ where: { userId: user.id }
1645
1570
  });
1646
1571
  await this.config.prisma.user.update({
1647
1572
  where: { id: user.id },
@@ -1694,7 +1619,7 @@ var TwoFaProcedureFactory = class {
1694
1619
  });
1695
1620
  }
1696
1621
  deregisterPushToken() {
1697
- return this.authProcedure.meta({ ignoreExpiration: true }).input(deregisterPushTokenSchema).mutation(async ({ ctx, input }) => {
1622
+ return this.authProcedure.input(deregisterPushTokenSchema).mutation(async ({ ctx, input }) => {
1698
1623
  this.checkConfig();
1699
1624
  const { userId } = ctx;
1700
1625
  const { pushToken } = input;
@@ -1813,7 +1738,6 @@ var createContext = ({ req, res }) => ({
1813
1738
  headers: req.headers,
1814
1739
  userId: null,
1815
1740
  sessionId: null,
1816
- refreshToken: null,
1817
1741
  socketId: null,
1818
1742
  ip: getClientIp(req),
1819
1743
  res
@@ -1872,12 +1796,12 @@ export {
1872
1796
  biometricVerifySchema,
1873
1797
  changePasswordSchema,
1874
1798
  cleanBase32String,
1875
- clearAuthCookies,
1799
+ clearAuthCookie,
1876
1800
  comparePassword,
1877
- createAccessToken,
1878
1801
  createAuthConfig,
1879
1802
  createAuthGuard,
1880
1803
  createAuthRouter,
1804
+ createAuthToken,
1881
1805
  createConsoleEmailAdapter,
1882
1806
  createNoopEmailAdapter,
1883
1807
  createOAuthVerifier,
@@ -1897,20 +1821,16 @@ export {
1897
1821
  isTokenExpiredError,
1898
1822
  isTokenInvalidError,
1899
1823
  loginSchema,
1900
- logoutSchema,
1901
1824
  oAuthLoginSchema,
1902
- otpLoginRequestSchema,
1903
- otpLoginVerifySchema,
1904
- parseAuthCookies,
1825
+ parseAuthCookie,
1905
1826
  requestPasswordResetSchema,
1906
1827
  resetPasswordSchema,
1907
- setAuthCookies,
1828
+ setAuthCookie,
1908
1829
  signupSchema,
1909
1830
  twoFaResetSchema,
1910
- twoFaSetupSchema,
1911
1831
  twoFaVerifySchema,
1912
1832
  validatePasswordStrength,
1913
- verifyAccessToken,
1833
+ verifyAuthToken,
1914
1834
  verifyEmailSchema,
1915
1835
  verifyTotp
1916
1836
  };
@@ -1,2 +1,2 @@
1
1
  import 'zod';
2
- export { m as AuthSchemas, C as ChangePasswordInput, n as CreatedSchemas, L as LoginInput, p as LoginSchemaInput, a as LogoutInput, O as OAuthLoginInput, q as OAuthSchemaInput, R as ResetPasswordInput, b as SignupInput, u as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, c as biometricVerifySchema, d as changePasswordSchema, w as checkPasswordResetSchema, x as createSchemas, y as deregisterPushTokenSchema, z as disableTwofaSchema, e as endAllSessionsSchema, B as getTwofaSecretSchema, l as loginSchema, f as logoutSchema, o as oAuthLoginSchema, g as otpLoginRequestSchema, h as otpLoginVerifySchema, D as registerPushTokenSchema, r as requestPasswordResetSchema, E as resendVerificationSchema, i as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, F as twoFaResetVerifySchema, j as twoFaSetupSchema, k as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-B41uikq7.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-yHGJ7C6_.mjs';
@@ -1,2 +1,2 @@
1
1
  import 'zod';
2
- export { m as AuthSchemas, C as ChangePasswordInput, n as CreatedSchemas, L as LoginInput, p as LoginSchemaInput, a as LogoutInput, O as OAuthLoginInput, q as OAuthSchemaInput, R as ResetPasswordInput, b as SignupInput, u as SignupSchemaInput, T as TwoFaVerifyInput, V as VerifyEmailInput, c as biometricVerifySchema, d as changePasswordSchema, w as checkPasswordResetSchema, x as createSchemas, y as deregisterPushTokenSchema, z as disableTwofaSchema, e as endAllSessionsSchema, B as getTwofaSecretSchema, l as loginSchema, f as logoutSchema, o as oAuthLoginSchema, g as otpLoginRequestSchema, h as otpLoginVerifySchema, D as registerPushTokenSchema, r as requestPasswordResetSchema, E as resendVerificationSchema, i as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, F as twoFaResetVerifySchema, j as twoFaSetupSchema, k as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-B41uikq7.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-yHGJ7C6_.js';
@@ -29,18 +29,13 @@ __export(validators_exports, {
29
29
  endAllSessionsSchema: () => endAllSessionsSchema,
30
30
  getTwofaSecretSchema: () => getTwofaSecretSchema,
31
31
  loginSchema: () => loginSchema,
32
- logoutSchema: () => logoutSchema,
33
32
  oAuthLoginSchema: () => oAuthLoginSchema,
34
- otpLoginRequestSchema: () => otpLoginRequestSchema,
35
- otpLoginVerifySchema: () => otpLoginVerifySchema,
36
33
  registerPushTokenSchema: () => registerPushTokenSchema,
37
34
  requestPasswordResetSchema: () => requestPasswordResetSchema,
38
- resendVerificationSchema: () => resendVerificationSchema,
39
35
  resetPasswordSchema: () => resetPasswordSchema,
40
36
  signupSchema: () => signupSchema,
41
37
  twoFaResetSchema: () => twoFaResetSchema,
42
38
  twoFaResetVerifySchema: () => twoFaResetVerifySchema,
43
- twoFaSetupSchema: () => twoFaSetupSchema,
44
39
  twoFaVerifySchema: () => twoFaVerifySchema,
45
40
  verifyEmailSchema: () => verifyEmailSchema
46
41
  });
@@ -87,9 +82,6 @@ var twoFaVerifySchema = import_zod.z.object({
87
82
  code: import_zod.z.string().min(6, { message: "Verification code is required" }),
88
83
  sessionId: import_zod.z.number().optional()
89
84
  });
90
- var twoFaSetupSchema = import_zod.z.object({
91
- code: import_zod.z.string().min(6, { message: "Verification code is required" })
92
- });
93
85
  var twoFaResetSchema = import_zod.z.object({
94
86
  username: import_zod.z.string().min(1),
95
87
  password: import_zod.z.string().min(1)
@@ -101,9 +93,6 @@ var twoFaResetVerifySchema = import_zod.z.object({
101
93
  var verifyEmailSchema = import_zod.z.object({
102
94
  code: import_zod.z.string().min(1, { message: "Verification code is required" })
103
95
  });
104
- var resendVerificationSchema = import_zod.z.object({
105
- email: import_zod.z.string().email().optional()
106
- });
107
96
  var biometricVerifySchema = import_zod.z.object({});
108
97
  var registerPushTokenSchema = import_zod.z.object({
109
98
  pushToken: import_zod.z.string().min(1, { message: "Push token is required" })
@@ -117,19 +106,9 @@ var getTwofaSecretSchema = import_zod.z.object({
117
106
  var disableTwofaSchema = import_zod.z.object({
118
107
  password: import_zod.z.string().min(1, { message: "Password is required" })
119
108
  });
120
- var logoutSchema = import_zod.z.object({
121
- allDevices: import_zod.z.boolean().optional().default(false)
122
- });
123
109
  var endAllSessionsSchema = import_zod.z.object({
124
110
  skipCurrentSession: import_zod.z.boolean().optional().default(true)
125
111
  });
126
- var otpLoginRequestSchema = import_zod.z.object({
127
- email: import_zod.z.string().email({ message: "Invalid email address" })
128
- });
129
- var otpLoginVerifySchema = import_zod.z.object({
130
- email: import_zod.z.string().email(),
131
- code: import_zod.z.number().min(1e5).max(999999)
132
- });
133
112
  function createSchemas(extensions) {
134
113
  return {
135
114
  signup: extensions?.signup ? signupSchema.merge(extensions.signup) : signupSchema,
@@ -148,18 +127,13 @@ function createSchemas(extensions) {
148
127
  endAllSessionsSchema,
149
128
  getTwofaSecretSchema,
150
129
  loginSchema,
151
- logoutSchema,
152
130
  oAuthLoginSchema,
153
- otpLoginRequestSchema,
154
- otpLoginVerifySchema,
155
131
  registerPushTokenSchema,
156
132
  requestPasswordResetSchema,
157
- resendVerificationSchema,
158
133
  resetPasswordSchema,
159
134
  signupSchema,
160
135
  twoFaResetSchema,
161
136
  twoFaResetVerifySchema,
162
- twoFaSetupSchema,
163
137
  twoFaVerifySchema,
164
138
  verifyEmailSchema
165
139
  });