@factiii/auth 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CLHDX2R2.mjs → chunk-PYVDWODF.mjs} +6 -5
- package/dist/{hooks-B4Kl294A.d.mts → hooks-B41uikq7.d.mts} +3 -3
- package/dist/{hooks-B4Kl294A.d.ts → hooks-B41uikq7.d.ts} +3 -3
- package/dist/index.d.mts +16 -14
- package/dist/index.d.ts +16 -14
- package/dist/index.js +51 -100
- package/dist/index.mjs +46 -97
- package/dist/validators.d.mts +1 -1
- package/dist/validators.d.ts +1 -1
- package/dist/validators.js +6 -5
- package/dist/validators.mjs +1 -2
- package/package.json +28 -5
- package/dist/chunk-CLHDX2R2.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/validators.js.map +0 -1
- package/dist/validators.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
twoFaSetupSchema,
|
|
22
22
|
twoFaVerifySchema,
|
|
23
23
|
verifyEmailSchema
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-PYVDWODF.mjs";
|
|
25
25
|
|
|
26
26
|
// src/middleware/authGuard.ts
|
|
27
27
|
import { TRPCError } from "@trpc/server";
|
|
@@ -30,22 +30,20 @@ import { TRPCError } from "@trpc/server";
|
|
|
30
30
|
function createNoopEmailAdapter() {
|
|
31
31
|
return {
|
|
32
32
|
async sendVerificationEmail(email, code) {
|
|
33
|
-
console.
|
|
33
|
+
console.debug(
|
|
34
34
|
`[NoopEmailAdapter] Would send verification email to ${email} with code ${code}`
|
|
35
35
|
);
|
|
36
36
|
},
|
|
37
37
|
async sendPasswordResetEmail(email, token) {
|
|
38
|
-
console.
|
|
38
|
+
console.debug(
|
|
39
39
|
`[NoopEmailAdapter] Would send password reset email to ${email} with token ${token}`
|
|
40
40
|
);
|
|
41
41
|
},
|
|
42
42
|
async sendOTPEmail(email, otp) {
|
|
43
|
-
console.
|
|
44
|
-
`[NoopEmailAdapter] Would send OTP email to ${email} with code ${otp}`
|
|
45
|
-
);
|
|
43
|
+
console.debug(`[NoopEmailAdapter] Would send OTP email to ${email} with code ${otp}`);
|
|
46
44
|
},
|
|
47
45
|
async sendLoginNotification(email, browserName, ip) {
|
|
48
|
-
console.
|
|
46
|
+
console.debug(
|
|
49
47
|
`[NoopEmailAdapter] Would send login notification to ${email} from ${browserName} (${ip})`
|
|
50
48
|
);
|
|
51
49
|
}
|
|
@@ -104,6 +102,7 @@ var defaultStorageKeys = {
|
|
|
104
102
|
};
|
|
105
103
|
var defaultFeatures = {
|
|
106
104
|
twoFa: true,
|
|
105
|
+
twoFaRequiresDevice: true,
|
|
107
106
|
oauth: { google: true, apple: true },
|
|
108
107
|
biometric: false,
|
|
109
108
|
emailVerification: true,
|
|
@@ -251,9 +250,7 @@ function decodeToken(token) {
|
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
function isJwtError(error) {
|
|
254
|
-
return error instanceof Error && ["TokenExpiredError", "JsonWebTokenError", "NotBeforeError"].includes(
|
|
255
|
-
error.name
|
|
256
|
-
);
|
|
253
|
+
return error instanceof Error && ["TokenExpiredError", "JsonWebTokenError", "NotBeforeError"].includes(error.name);
|
|
257
254
|
}
|
|
258
255
|
function isTokenExpiredError(error) {
|
|
259
256
|
return isJwtError(error) && error.name === "TokenExpiredError";
|
|
@@ -307,11 +304,7 @@ ${errorStack}` : null,
|
|
|
307
304
|
select: { id: true, userId: true, socketId: true }
|
|
308
305
|
});
|
|
309
306
|
if (session) {
|
|
310
|
-
await config.hooks.onSessionRevoked(
|
|
311
|
-
session.userId,
|
|
312
|
-
session.socketId,
|
|
313
|
-
description
|
|
314
|
-
);
|
|
307
|
+
await config.hooks.onSessionRevoked(session.userId, session.socketId, description);
|
|
315
308
|
}
|
|
316
309
|
}
|
|
317
310
|
} catch {
|
|
@@ -380,13 +373,7 @@ ${errorStack}` : null,
|
|
|
380
373
|
});
|
|
381
374
|
}
|
|
382
375
|
if (session.user.status === "BANNED") {
|
|
383
|
-
await revokeSession(
|
|
384
|
-
ctx,
|
|
385
|
-
session.id,
|
|
386
|
-
"Session revoked: User banned",
|
|
387
|
-
void 0,
|
|
388
|
-
path
|
|
389
|
-
);
|
|
376
|
+
await revokeSession(ctx, session.id, "Session revoked: User banned", void 0, path);
|
|
390
377
|
throw new TRPCError({
|
|
391
378
|
message: "Unauthorized",
|
|
392
379
|
code: "UNAUTHORIZED"
|
|
@@ -394,9 +381,7 @@ ${errorStack}` : null,
|
|
|
394
381
|
}
|
|
395
382
|
if (config.features?.biometric && config.hooks?.getBiometricTimeout) {
|
|
396
383
|
const timeoutMs = await config.hooks.getBiometricTimeout();
|
|
397
|
-
if (timeoutMs !== null && !["auth.refresh", "auth.verifyBiometric", "auth.logout"].includes(
|
|
398
|
-
path
|
|
399
|
-
)) {
|
|
384
|
+
if (timeoutMs !== null && !["auth.refresh", "auth.verifyBiometric", "auth.logout"].includes(path)) {
|
|
400
385
|
if (!session.user.verifiedHumanAt) {
|
|
401
386
|
throw new TRPCError({
|
|
402
387
|
message: "Biometric verification not completed. Please verify again.",
|
|
@@ -404,9 +389,7 @@ ${errorStack}` : null,
|
|
|
404
389
|
});
|
|
405
390
|
}
|
|
406
391
|
const now = /* @__PURE__ */ new Date();
|
|
407
|
-
const verificationExpiry = new Date(
|
|
408
|
-
session.user.verifiedHumanAt.getTime() + timeoutMs
|
|
409
|
-
);
|
|
392
|
+
const verificationExpiry = new Date(session.user.verifiedHumanAt.getTime() + timeoutMs);
|
|
410
393
|
if (now > verificationExpiry) {
|
|
411
394
|
throw new TRPCError({
|
|
412
395
|
message: "Biometric verification expired. Please verify again.",
|
|
@@ -478,13 +461,7 @@ ${errorStack}` : null,
|
|
|
478
461
|
});
|
|
479
462
|
}
|
|
480
463
|
if (err instanceof TRPCError && err.code === "UNAUTHORIZED") {
|
|
481
|
-
await revokeSession(
|
|
482
|
-
ctx,
|
|
483
|
-
null,
|
|
484
|
-
"Session revoked: Unauthorized",
|
|
485
|
-
errorStack,
|
|
486
|
-
path
|
|
487
|
-
);
|
|
464
|
+
await revokeSession(ctx, null, "Session revoked: Unauthorized", errorStack, path);
|
|
488
465
|
throw new TRPCError({
|
|
489
466
|
message: "Unauthorized",
|
|
490
467
|
code: "UNAUTHORIZED"
|
|
@@ -496,13 +473,7 @@ ${errorStack}` : null,
|
|
|
496
473
|
if (!meta?.authRequired) {
|
|
497
474
|
return next({ ctx: { ...ctx, userId: 0 } });
|
|
498
475
|
}
|
|
499
|
-
await revokeSession(
|
|
500
|
-
ctx,
|
|
501
|
-
null,
|
|
502
|
-
"Session revoked: No token sent",
|
|
503
|
-
void 0,
|
|
504
|
-
path
|
|
505
|
-
);
|
|
476
|
+
await revokeSession(ctx, null, "Session revoked: No token sent", void 0, path);
|
|
506
477
|
throw new TRPCError({ message: "Unauthorized", code: "UNAUTHORIZED" });
|
|
507
478
|
}
|
|
508
479
|
});
|
|
@@ -523,25 +494,19 @@ function detectBrowser(userAgent) {
|
|
|
523
494
|
return "iOS Browser (Chrome)";
|
|
524
495
|
if (/iphone|ipad|ipod/i.test(userAgent) && /fxios/i.test(userAgent))
|
|
525
496
|
return "iOS Browser (Firefox)";
|
|
526
|
-
if (/iphone|ipad|ipod/i.test(userAgent) && /edg\//i.test(userAgent))
|
|
527
|
-
return "iOS Browser (Edge)";
|
|
497
|
+
if (/iphone|ipad|ipod/i.test(userAgent) && /edg\//i.test(userAgent)) return "iOS Browser (Edge)";
|
|
528
498
|
if (/android/i.test(userAgent) && !/chrome|firefox|samsungbrowser|opr\/|edg\//i.test(userAgent)) {
|
|
529
499
|
return "Android App";
|
|
530
500
|
}
|
|
531
|
-
if (/android/i.test(userAgent) && /chrome/i.test(userAgent))
|
|
532
|
-
|
|
533
|
-
if (/android/i.test(userAgent) && /firefox/i.test(userAgent))
|
|
534
|
-
return "Android Browser (Firefox)";
|
|
501
|
+
if (/android/i.test(userAgent) && /chrome/i.test(userAgent)) return "Android Browser (Chrome)";
|
|
502
|
+
if (/android/i.test(userAgent) && /firefox/i.test(userAgent)) return "Android Browser (Firefox)";
|
|
535
503
|
if (/android/i.test(userAgent) && /samsungbrowser/i.test(userAgent))
|
|
536
504
|
return "Android Browser (Samsung)";
|
|
537
|
-
if (/android/i.test(userAgent) && /opr\//i.test(userAgent))
|
|
538
|
-
|
|
539
|
-
if (/android/i.test(userAgent) && /edg\//i.test(userAgent))
|
|
540
|
-
return "Android Browser (Edge)";
|
|
505
|
+
if (/android/i.test(userAgent) && /opr\//i.test(userAgent)) return "Android Browser (Opera)";
|
|
506
|
+
if (/android/i.test(userAgent) && /edg\//i.test(userAgent)) return "Android Browser (Edge)";
|
|
541
507
|
if (/chrome|chromium/i.test(userAgent)) return "Chrome";
|
|
542
508
|
if (/firefox/i.test(userAgent)) return "Firefox";
|
|
543
|
-
if (/safari/i.test(userAgent) && !/chrome|chromium|crios/i.test(userAgent))
|
|
544
|
-
return "Safari";
|
|
509
|
+
if (/safari/i.test(userAgent) && !/chrome|chromium|crios/i.test(userAgent)) return "Safari";
|
|
545
510
|
if (/opr\//i.test(userAgent)) return "Opera";
|
|
546
511
|
if (/edg\//i.test(userAgent)) return "Edge";
|
|
547
512
|
return "Unknown";
|
|
@@ -575,16 +540,10 @@ function createOAuthVerifier(keys) {
|
|
|
575
540
|
return async function verifyOAuthToken(provider, token, extra) {
|
|
576
541
|
if (provider === "GOOGLE") {
|
|
577
542
|
if (!keys.google?.clientId) {
|
|
578
|
-
throw new OAuthVerificationError(
|
|
579
|
-
"Google OAuth configuration missing",
|
|
580
|
-
500
|
|
581
|
-
);
|
|
543
|
+
throw new OAuthVerificationError("Google OAuth configuration missing", 500);
|
|
582
544
|
}
|
|
583
545
|
if (!googleClient) {
|
|
584
|
-
throw new OAuthVerificationError(
|
|
585
|
-
"Google OAuth client not initialized",
|
|
586
|
-
500
|
|
587
|
-
);
|
|
546
|
+
throw new OAuthVerificationError("Google OAuth client not initialized", 500);
|
|
588
547
|
}
|
|
589
548
|
const audience = [keys.google.clientId];
|
|
590
549
|
if (keys.google.iosClientId) {
|
|
@@ -605,10 +564,7 @@ function createOAuthVerifier(keys) {
|
|
|
605
564
|
}
|
|
606
565
|
if (provider === "APPLE") {
|
|
607
566
|
if (!keys.apple?.clientId) {
|
|
608
|
-
throw new OAuthVerificationError(
|
|
609
|
-
"Apple OAuth configuration missing",
|
|
610
|
-
500
|
|
611
|
-
);
|
|
567
|
+
throw new OAuthVerificationError("Apple OAuth configuration missing", 500);
|
|
612
568
|
}
|
|
613
569
|
const audience = [keys.apple.clientId];
|
|
614
570
|
if (keys.apple.iosClientId) {
|
|
@@ -1014,7 +970,11 @@ var BaseProcedureFactory = class {
|
|
|
1014
970
|
});
|
|
1015
971
|
for (const session of sessionsToRevoke) {
|
|
1016
972
|
if (this.config.hooks?.onSessionRevoked) {
|
|
1017
|
-
await this.config.hooks.onSessionRevoked(
|
|
973
|
+
await this.config.hooks.onSessionRevoked(
|
|
974
|
+
session.id,
|
|
975
|
+
session.socketId,
|
|
976
|
+
"End all sessions"
|
|
977
|
+
);
|
|
1018
978
|
}
|
|
1019
979
|
}
|
|
1020
980
|
if (!skipCurrentSession) {
|
|
@@ -1343,14 +1303,14 @@ var OAuthLoginProcedureFactory = class {
|
|
|
1343
1303
|
}
|
|
1344
1304
|
const { email, oauthId } = await this.verifyOAuthToken(provider, idToken, appleUser);
|
|
1345
1305
|
if (!email) {
|
|
1346
|
-
throw new TRPCError5({
|
|
1306
|
+
throw new TRPCError5({
|
|
1307
|
+
code: "BAD_REQUEST",
|
|
1308
|
+
message: "Email not provided by OAuth provider"
|
|
1309
|
+
});
|
|
1347
1310
|
}
|
|
1348
1311
|
let user = await this.config.prisma.user.findFirst({
|
|
1349
1312
|
where: {
|
|
1350
|
-
OR: [
|
|
1351
|
-
{ email: { equals: email, mode: "insensitive" } },
|
|
1352
|
-
{ oauthId: { equals: oauthId } }
|
|
1353
|
-
]
|
|
1313
|
+
OR: [{ email: { equals: email, mode: "insensitive" } }, { oauthId: { equals: oauthId } }]
|
|
1354
1314
|
},
|
|
1355
1315
|
select: {
|
|
1356
1316
|
id: true,
|
|
@@ -1500,15 +1460,17 @@ var TwoFaProcedureFactory = class {
|
|
|
1500
1460
|
if (user.twoFaEnabled) {
|
|
1501
1461
|
throw new TRPCError6({ code: "BAD_REQUEST", message: "2FA already enabled." });
|
|
1502
1462
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
if (!checkSession?.deviceId) {
|
|
1508
|
-
throw new TRPCError6({
|
|
1509
|
-
code: "BAD_REQUEST",
|
|
1510
|
-
message: "You must be logged in on mobile to enable 2FA."
|
|
1463
|
+
if (this.config.features.twoFaRequiresDevice !== false) {
|
|
1464
|
+
const checkSession = await this.config.prisma.session.findFirst({
|
|
1465
|
+
where: { userId, id: sessionId },
|
|
1466
|
+
select: { deviceId: true }
|
|
1511
1467
|
});
|
|
1468
|
+
if (!checkSession?.deviceId) {
|
|
1469
|
+
throw new TRPCError6({
|
|
1470
|
+
code: "BAD_REQUEST",
|
|
1471
|
+
message: "You must be logged in on mobile to enable 2FA."
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1512
1474
|
}
|
|
1513
1475
|
await this.config.prisma.session.updateMany({
|
|
1514
1476
|
where: { userId, revokedAt: null, NOT: { id: sessionId } },
|
|
@@ -1827,10 +1789,7 @@ function getClientIp(req) {
|
|
|
1827
1789
|
}
|
|
1828
1790
|
|
|
1829
1791
|
// src/router.ts
|
|
1830
|
-
var createContext = ({
|
|
1831
|
-
req,
|
|
1832
|
-
res
|
|
1833
|
-
}) => ({
|
|
1792
|
+
var createContext = ({ req, res }) => ({
|
|
1834
1793
|
headers: req.headers,
|
|
1835
1794
|
userId: null,
|
|
1836
1795
|
sessionId: null,
|
|
@@ -1843,9 +1802,7 @@ var AuthRouterFactory = class {
|
|
|
1843
1802
|
constructor(userConfig) {
|
|
1844
1803
|
this.userConfig = userConfig;
|
|
1845
1804
|
this.config = createAuthConfig(this.userConfig);
|
|
1846
|
-
this.schemas = createSchemas(
|
|
1847
|
-
this.config.schemaExtensions
|
|
1848
|
-
);
|
|
1805
|
+
this.schemas = createSchemas(this.config.schemaExtensions);
|
|
1849
1806
|
this.t = createTrpcBuilder(this.config);
|
|
1850
1807
|
this.authGuard = createAuthGuard(this.config, this.t);
|
|
1851
1808
|
this.procedure = createBaseProcedure(this.t, this.authGuard);
|
|
@@ -1857,10 +1814,7 @@ var AuthRouterFactory = class {
|
|
|
1857
1814
|
this.procedure,
|
|
1858
1815
|
this.authProcedure
|
|
1859
1816
|
);
|
|
1860
|
-
const biometricRoutes = new BiometricProcedureFactory(
|
|
1861
|
-
this.config,
|
|
1862
|
-
this.authProcedure
|
|
1863
|
-
);
|
|
1817
|
+
const biometricRoutes = new BiometricProcedureFactory(this.config, this.authProcedure);
|
|
1864
1818
|
const emailVerificationRoutes = new EmailVerificationProcedureFactory(
|
|
1865
1819
|
this.config,
|
|
1866
1820
|
this.authProcedure
|
|
@@ -1869,11 +1823,7 @@ var AuthRouterFactory = class {
|
|
|
1869
1823
|
this.config,
|
|
1870
1824
|
this.procedure
|
|
1871
1825
|
);
|
|
1872
|
-
const twoFaRoutes = new TwoFaProcedureFactory(
|
|
1873
|
-
this.config,
|
|
1874
|
-
this.procedure,
|
|
1875
|
-
this.authProcedure
|
|
1876
|
-
);
|
|
1826
|
+
const twoFaRoutes = new TwoFaProcedureFactory(this.config, this.procedure, this.authProcedure);
|
|
1877
1827
|
return this.t.router({
|
|
1878
1828
|
...baseRoutes.createBaseProcedures(this.schemas),
|
|
1879
1829
|
...oAuthLoginRoutes.createOAuthLoginProcedures(this.schemas),
|
|
@@ -1944,4 +1894,3 @@ export {
|
|
|
1944
1894
|
verifyEmailSchema,
|
|
1945
1895
|
verifyTotp
|
|
1946
1896
|
};
|
|
1947
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/validators.d.mts
CHANGED
|
@@ -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-
|
|
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';
|
package/dist/validators.d.ts
CHANGED
|
@@ -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-
|
|
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';
|
package/dist/validators.js
CHANGED
|
@@ -51,8 +51,10 @@ var signupSchema = import_zod.z.object({
|
|
|
51
51
|
username: import_zod.z.string().min(1, { message: "Username is required" }).max(30, { message: "Username must be 30 characters or less" }).regex(usernameValidationRegex, {
|
|
52
52
|
message: "Username can only contain letters, numbers, and underscores"
|
|
53
53
|
}),
|
|
54
|
-
email: import_zod.z.string().email({ message: "Invalid email address" }),
|
|
55
|
-
password: import_zod.z.string().min(6, { message: "Password must contain at least 6 characters" })
|
|
54
|
+
email: import_zod.z.string().max(254, { message: "Email must be 254 characters or less" }).email({ message: "Invalid email address" }),
|
|
55
|
+
password: import_zod.z.string().min(6, { message: "Password must contain at least 6 characters" }).max(72, { message: "Password must be 72 characters or less" }).refine((val) => val.trim().length >= 6, {
|
|
56
|
+
message: "Password cannot be only whitespace"
|
|
57
|
+
})
|
|
56
58
|
});
|
|
57
59
|
var loginSchema = import_zod.z.object({
|
|
58
60
|
username: import_zod.z.string().min(1, { message: "Username or email is required" }),
|
|
@@ -72,14 +74,14 @@ var requestPasswordResetSchema = import_zod.z.object({
|
|
|
72
74
|
});
|
|
73
75
|
var resetPasswordSchema = import_zod.z.object({
|
|
74
76
|
token: import_zod.z.string().min(1, { message: "Reset token is required" }),
|
|
75
|
-
password: import_zod.z.string().min(6, { message: "Password must contain at least 6 characters" })
|
|
77
|
+
password: import_zod.z.string().min(6, { message: "Password must contain at least 6 characters" }).max(72, { message: "Password must be 72 characters or less" })
|
|
76
78
|
});
|
|
77
79
|
var checkPasswordResetSchema = import_zod.z.object({
|
|
78
80
|
token: import_zod.z.string().min(1, { message: "Reset token is required" })
|
|
79
81
|
});
|
|
80
82
|
var changePasswordSchema = import_zod.z.object({
|
|
81
83
|
currentPassword: import_zod.z.string().min(1, { message: "Current password is required" }),
|
|
82
|
-
newPassword: import_zod.z.string().min(6, { message: "New password must contain at least 6 characters" })
|
|
84
|
+
newPassword: import_zod.z.string().min(6, { message: "New password must contain at least 6 characters" }).max(72, { message: "Password must be 72 characters or less" })
|
|
83
85
|
});
|
|
84
86
|
var twoFaVerifySchema = import_zod.z.object({
|
|
85
87
|
code: import_zod.z.string().min(6, { message: "Verification code is required" }),
|
|
@@ -161,4 +163,3 @@ function createSchemas(extensions) {
|
|
|
161
163
|
twoFaVerifySchema,
|
|
162
164
|
verifyEmailSchema
|
|
163
165
|
});
|
|
164
|
-
//# sourceMappingURL=validators.js.map
|
package/dist/validators.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
twoFaSetupSchema,
|
|
23
23
|
twoFaVerifySchema,
|
|
24
24
|
verifyEmailSchema
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-PYVDWODF.mjs";
|
|
26
26
|
export {
|
|
27
27
|
biometricVerifySchema,
|
|
28
28
|
changePasswordSchema,
|
|
@@ -48,4 +48,3 @@ export {
|
|
|
48
48
|
twoFaVerifySchema,
|
|
49
49
|
verifyEmailSchema
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=validators.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factiii/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -53,10 +53,16 @@
|
|
|
53
53
|
"build": "tsup",
|
|
54
54
|
"dev": "tsup --watch",
|
|
55
55
|
"check-types": "tsc --noEmit",
|
|
56
|
-
"lint": "eslint src
|
|
57
|
-
"lint:fix": "eslint src --
|
|
56
|
+
"lint": "eslint src",
|
|
57
|
+
"lint:fix": "eslint src --fix",
|
|
58
|
+
"format": "prettier --check src",
|
|
59
|
+
"format:fix": "prettier --write src",
|
|
58
60
|
"clean": "rm -rf dist node_modules/.cache .turbo",
|
|
59
|
-
"prepublishOnly": "npm run build"
|
|
61
|
+
"prepublishOnly": "npm run build",
|
|
62
|
+
"e2e": "pnpm e2e:db:up && playwright test --reporter=list; pnpm e2e:db:down",
|
|
63
|
+
"e2e:ui": "pnpm e2e:db:up && playwright test --ui",
|
|
64
|
+
"e2e:db:up": "docker compose -f e2e/docker-compose.yml up -d --wait && prisma generate --schema=e2e/server/schema.prisma --config=e2e/server/prisma.config.ts && prisma migrate reset --schema=e2e/server/schema.prisma --config=e2e/server/prisma.config.ts --force",
|
|
65
|
+
"e2e:db:down": "docker compose -f e2e/docker-compose.yml down"
|
|
60
66
|
},
|
|
61
67
|
"dependencies": {
|
|
62
68
|
"@trpc/server": "11.8.0",
|
|
@@ -83,22 +89,39 @@
|
|
|
83
89
|
}
|
|
84
90
|
},
|
|
85
91
|
"devDependencies": {
|
|
92
|
+
"@playwright/test": "^1.58.1",
|
|
93
|
+
"@prisma/adapter-better-sqlite3": "^7.3.0",
|
|
94
|
+
"@prisma/adapter-pg": "^7.3.0",
|
|
86
95
|
"@prisma/client": "^7.1.0",
|
|
96
|
+
"@trpc/client": "^11.8.0",
|
|
87
97
|
"@trpc/server": "11.8.0",
|
|
88
98
|
"@types/bcryptjs": "^2.4.6",
|
|
99
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
89
100
|
"@types/jsonwebtoken": "^9.0.9",
|
|
90
101
|
"@types/node": "^20.19.0",
|
|
102
|
+
"@types/pg": "^8.16.0",
|
|
103
|
+
"@types/react": "^19.2.11",
|
|
104
|
+
"@types/react-dom": "^19.2.3",
|
|
91
105
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
92
106
|
"@typescript-eslint/parser": "^7.18.0",
|
|
107
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
108
|
+
"better-sqlite3": "^12.6.2",
|
|
93
109
|
"eslint": "^8.57.0",
|
|
110
|
+
"pg": "^8.18.0",
|
|
111
|
+
"prettier": "^3.8.1",
|
|
94
112
|
"prisma": "^7.1.0",
|
|
113
|
+
"react": "^19.2.4",
|
|
114
|
+
"react-dom": "^19.2.4",
|
|
115
|
+
"react-router-dom": "^7.2.0",
|
|
95
116
|
"superjson": "^1.13.3",
|
|
96
117
|
"tsup": "^8.3.5",
|
|
118
|
+
"tsx": "^4.21.0",
|
|
97
119
|
"typescript": "5.9.3",
|
|
120
|
+
"vite": "^7.3.1",
|
|
98
121
|
"zod": "3.24.2"
|
|
99
122
|
},
|
|
100
123
|
"engines": {
|
|
101
124
|
"node": ">=18.0.0"
|
|
102
125
|
},
|
|
103
|
-
"packageManager": "pnpm@10.26.0
|
|
126
|
+
"packageManager": "pnpm@10.26.0"
|
|
104
127
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validators.ts"],"sourcesContent":["import { z, type AnyZodObject } from 'zod';\n\nimport type { SchemaExtensions } from './types/hooks';\n\n/**\n * Username validation regex - allows letters, numbers, and underscores\n */\nconst usernameValidationRegex = /^[a-zA-Z0-9_]+$/;\n\n/**\n * Schema for user registration\n */\nexport const signupSchema = z.object({\n username: z\n .string()\n .min(1, { message: 'Username is required' })\n .max(30, { message: 'Username must be 30 characters or less' })\n .regex(usernameValidationRegex, {\n message: 'Username can only contain letters, numbers, and underscores'\n }),\n email: z.string().email({ message: 'Invalid email address' }),\n password: z\n .string()\n .min(6, { message: 'Password must contain at least 6 characters' })\n});\n\n/**\n * Schema for user login\n */\nexport const loginSchema = z.object({\n username: z.string().min(1, { message: 'Username or email is required' }),\n password: z.string().min(1, { message: 'Password is required' }),\n code: z.string().optional() // 2FA code\n});\n\n/**\n * Schema for OAuth login\n */\nexport const oAuthLoginSchema = z.object({\n idToken: z.string(),\n user: z\n .object({\n email: z.string().email().optional()\n })\n .optional(),\n provider: z.enum(['GOOGLE', 'APPLE'])\n});\n\n/**\n * Schema for password reset request\n */\nexport const requestPasswordResetSchema = z.object({\n email: z.string().email({ message: 'Invalid email address' })\n});\n\n/**\n * Schema for password reset confirmation\n */\nexport const resetPasswordSchema = z.object({\n token: z.string().min(1, { message: 'Reset token is required' }),\n password: z\n .string()\n .min(6, { message: 'Password must contain at least 6 characters' })\n});\n\n/**\n * Schema for checking password reset token\n */\nexport const checkPasswordResetSchema = z.object({\n token: z.string().min(1, { message: 'Reset token is required' })\n});\n\n/**\n * Schema for changing password (authenticated)\n */\nexport const changePasswordSchema = z.object({\n currentPassword: z\n .string()\n .min(1, { message: 'Current password is required' }),\n newPassword: z\n .string()\n .min(6, { message: 'New password must contain at least 6 characters' })\n});\n\n/**\n * Schema for 2FA verification\n */\nexport const twoFaVerifySchema = z.object({\n code: z.string().min(6, { message: 'Verification code is required' }),\n sessionId: z.number().optional()\n});\n\n/**\n * Schema for 2FA setup\n */\nexport const twoFaSetupSchema = z.object({\n code: z.string().min(6, { message: 'Verification code is required' })\n});\n\n/**\n * Schema for 2FA reset request\n */\nexport const twoFaResetSchema = z.object({\n username: z.string().min(1),\n password: z.string().min(1)\n});\n\n/**\n * Schema for 2FA reset verification\n */\nexport const twoFaResetVerifySchema = z.object({\n code: z.number().min(100000).max(999999),\n username: z.string().min(1)\n});\n\n/**\n * Schema for email verification\n */\nexport const verifyEmailSchema = z.object({\n code: z.string().min(1, { message: 'Verification code is required' })\n});\n\n/**\n * Schema for resending verification email\n */\nexport const resendVerificationSchema = z.object({\n email: z.string().email().optional()\n});\n\n/**\n * Schema for biometric verification\n */\nexport const biometricVerifySchema = z.object({});\n\n/**\n * Schema for push token registration\n */\nexport const registerPushTokenSchema = z.object({\n pushToken: z.string().min(1, { message: 'Push token is required' })\n});\n\n/**\n * Schema for push token deregistration\n */\nexport const deregisterPushTokenSchema = z.object({\n pushToken: z.string().min(1, { message: 'Push token is required' })\n});\n\n/**\n * Schema for getting 2FA secret\n */\nexport const getTwofaSecretSchema = z.object({\n pushCode: z.string().min(6, { message: 'Push code is required' })\n});\n\n/**\n * Schema for disabling 2FA\n */\nexport const disableTwofaSchema = z.object({\n password: z.string().min(1, { message: 'Password is required' })\n});\n\n/**\n * Schema for logout\n */\nexport const logoutSchema = z.object({\n allDevices: z.boolean().optional().default(false)\n});\n\n/**\n * Schema for ending all sessions\n */\nexport const endAllSessionsSchema = z.object({\n skipCurrentSession: z.boolean().optional().default(true)\n});\n\n/**\n * Schema for OTP-based login request\n */\nexport const otpLoginRequestSchema = z.object({\n email: z.string().email({ message: 'Invalid email address' })\n});\n\n/**\n * Schema for OTP-based login verification\n */\nexport const otpLoginVerifySchema = z.object({\n email: z.string().email(),\n code: z.number().min(100000).max(999999)\n});\n\nexport type SignupInput = z.infer<typeof signupSchema>;\nexport type LoginInput = z.infer<typeof loginSchema>;\nexport type OAuthLoginInput = z.infer<typeof oAuthLoginSchema>;\nexport type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;\nexport type ChangePasswordInput = z.infer<typeof changePasswordSchema>;\nexport type TwoFaVerifyInput = z.infer<typeof twoFaVerifySchema>;\nexport type VerifyEmailInput = z.infer<typeof verifyEmailSchema>;\nexport type LogoutInput = z.infer<typeof logoutSchema>;\n\n/** Schemas used by auth procedures */\nexport interface AuthSchemas {\n signup: AnyZodObject;\n login: AnyZodObject;\n oauth: AnyZodObject;\n}\n\n\n/**\n * Compute merged ZodObject type.\n * When TExt is defined, produces a schema with both base and extension shapes.\n * When TExt is undefined, produces the base schema.\n */\ntype MergedSchema<TBase extends AnyZodObject, TExt extends AnyZodObject | undefined> =\n [TExt] extends [AnyZodObject]\n ? z.ZodObject<TBase['shape'] & TExt['shape'], 'strip', z.ZodTypeAny>\n : TBase;\n\n/** Result type from createSchemas - preserves concrete schema types */\nexport type CreatedSchemas<TExtensions extends SchemaExtensions = {}> = {\n signup: MergedSchema<typeof signupSchema, TExtensions['signup']>;\n login: MergedSchema<typeof loginSchema, TExtensions['login']>;\n oauth: MergedSchema<typeof oAuthLoginSchema, TExtensions['oauth']>;\n};\n\nexport type SignupSchemaInput<TExtensions extends SchemaExtensions = {}> =\n SignupInput & (TExtensions['signup'] extends AnyZodObject ? z.infer<TExtensions['signup']> : {});\n\nexport type LoginSchemaInput<TExtensions extends SchemaExtensions = {}> =\n LoginInput & (TExtensions['login'] extends AnyZodObject ? z.infer<TExtensions['login']> : {});\n\nexport type OAuthSchemaInput<TExtensions extends SchemaExtensions = {}> =\n OAuthLoginInput & (TExtensions['oauth'] extends AnyZodObject ? z.infer<TExtensions['oauth']> : {});\n\n/** Create schemas with optional extensions merged in */\nexport function createSchemas<TExtensions extends SchemaExtensions = {}>(\n extensions?: TExtensions\n): CreatedSchemas<TExtensions> {\n return {\n signup: extensions?.signup\n ? signupSchema.merge(extensions.signup)\n : signupSchema,\n login: extensions?.login\n ? loginSchema.merge(extensions.login)\n : loginSchema,\n oauth: extensions?.oauth\n ? oAuthLoginSchema.merge(extensions.oauth)\n : oAuthLoginSchema\n } as CreatedSchemas<TExtensions>;\n}\n"],"mappings":";AAAA,SAAS,SAA4B;AAOrC,IAAM,0BAA0B;AAKzB,IAAM,eAAe,EAAE,OAAO;AAAA,EACnC,UAAU,EACP,OAAO,EACP,IAAI,GAAG,EAAE,SAAS,uBAAuB,CAAC,EAC1C,IAAI,IAAI,EAAE,SAAS,yCAAyC,CAAC,EAC7D,MAAM,yBAAyB;AAAA,IAC9B,SAAS;AAAA,EACX,CAAC;AAAA,EACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,wBAAwB,CAAC;AAAA,EAC5D,UAAU,EACP,OAAO,EACP,IAAI,GAAG,EAAE,SAAS,8CAA8C,CAAC;AACtE,CAAC;AAKM,IAAM,cAAc,EAAE,OAAO;AAAA,EAClC,UAAU,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS,gCAAgC,CAAC;AAAA,EACxE,UAAU,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS,uBAAuB,CAAC;AAAA,EAC/D,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA;AAC5B,CAAC;AAKM,IAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,SAAS,EAAE,OAAO;AAAA,EAClB,MAAM,EACH,OAAO;AAAA,IACN,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS;AAAA,EACrC,CAAC,EACA,SAAS;AAAA,EACZ,UAAU,EAAE,KAAK,CAAC,UAAU,OAAO,CAAC;AACtC,CAAC;AAKM,IAAM,6BAA6B,EAAE,OAAO;AAAA,EACjD,OAAO,EAAE,OAAO,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