@factiii/auth 0.4.1 → 0.5.2
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.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +25 -14
- package/dist/index.mjs +25 -14
- package/dist/validators.d.mts +1 -1
- package/dist/validators.d.ts +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +4 -2
- package/dist/{hooks-yHGJ7C6_.d.mts → hooks-BXNxNK4S.d.mts} +2 -2
- package/dist/{hooks-yHGJ7C6_.d.ts → hooks-BXNxNK4S.d.ts} +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ import { PrismaClient } from '@prisma/client';
|
|
|
6
6
|
import * as _trpc_server from '@trpc/server';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
|
|
9
|
-
import { S as SchemaExtensions, A as AuthHooks } from './hooks-
|
|
10
|
-
export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-
|
|
9
|
+
import { S as SchemaExtensions, A as AuthHooks } from './hooks-BXNxNK4S.mjs';
|
|
10
|
+
export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-BXNxNK4S.mjs';
|
|
11
11
|
|
|
12
12
|
//# sourceMappingURL=TRPCError.d.ts.map
|
|
13
13
|
//#endregion
|
|
@@ -659,12 +659,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
659
659
|
email: zod.ZodString;
|
|
660
660
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
661
661
|
}, "strip", zod.ZodTypeAny, {
|
|
662
|
-
username: string;
|
|
663
662
|
email: string;
|
|
663
|
+
username: string;
|
|
664
664
|
password: string;
|
|
665
665
|
}, {
|
|
666
|
-
username: string;
|
|
667
666
|
email: string;
|
|
667
|
+
username: string;
|
|
668
668
|
password: string;
|
|
669
669
|
}>>["in"] extends infer T_7 ? T_7 extends inferParser<[TExtensions["signup"]] extends [zod.AnyZodObject] ? zod.ZodObject<{
|
|
670
670
|
username: zod.ZodString;
|
|
@@ -683,12 +683,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
683
683
|
email: zod.ZodString;
|
|
684
684
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
685
685
|
}, "strip", zod.ZodTypeAny, {
|
|
686
|
-
username: string;
|
|
687
686
|
email: string;
|
|
687
|
+
username: string;
|
|
688
688
|
password: string;
|
|
689
689
|
}, {
|
|
690
|
-
username: string;
|
|
691
690
|
email: string;
|
|
691
|
+
username: string;
|
|
692
692
|
password: string;
|
|
693
693
|
}>>["in"] ? T_7 extends _trpc_server.TRPCUnsetMarker ? void : T_7 : never : never;
|
|
694
694
|
output: {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { PrismaClient } from '@prisma/client';
|
|
|
6
6
|
import * as _trpc_server from '@trpc/server';
|
|
7
7
|
import * as zod from 'zod';
|
|
8
8
|
import { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
|
|
9
|
-
import { S as SchemaExtensions, A as AuthHooks } from './hooks-
|
|
10
|
-
export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-
|
|
9
|
+
import { S as SchemaExtensions, A as AuthHooks } from './hooks-BXNxNK4S.js';
|
|
10
|
+
export { C as ChangePasswordInput, L as LoginInput, O as OAuthLoginInput, R as ResetPasswordInput, a as SignupInput, T as TwoFaVerifyInput, V as VerifyEmailInput, b as biometricVerifySchema, c as changePasswordSchema, e as endAllSessionsSchema, l as loginSchema, o as oAuthLoginSchema, r as requestPasswordResetSchema, d as resetPasswordSchema, s as signupSchema, t as twoFaResetSchema, f as twoFaVerifySchema, v as verifyEmailSchema } from './hooks-BXNxNK4S.js';
|
|
11
11
|
|
|
12
12
|
//# sourceMappingURL=TRPCError.d.ts.map
|
|
13
13
|
//#endregion
|
|
@@ -659,12 +659,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
659
659
|
email: zod.ZodString;
|
|
660
660
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
661
661
|
}, "strip", zod.ZodTypeAny, {
|
|
662
|
-
username: string;
|
|
663
662
|
email: string;
|
|
663
|
+
username: string;
|
|
664
664
|
password: string;
|
|
665
665
|
}, {
|
|
666
|
-
username: string;
|
|
667
666
|
email: string;
|
|
667
|
+
username: string;
|
|
668
668
|
password: string;
|
|
669
669
|
}>>["in"] extends infer T_7 ? T_7 extends inferParser<[TExtensions["signup"]] extends [zod.AnyZodObject] ? zod.ZodObject<{
|
|
670
670
|
username: zod.ZodString;
|
|
@@ -683,12 +683,12 @@ declare function createAuthRouter<TExtensions extends SchemaExtensions = {}>(con
|
|
|
683
683
|
email: zod.ZodString;
|
|
684
684
|
password: zod.ZodEffects<zod.ZodString, string, string>;
|
|
685
685
|
}, "strip", zod.ZodTypeAny, {
|
|
686
|
-
username: string;
|
|
687
686
|
email: string;
|
|
687
|
+
username: string;
|
|
688
688
|
password: string;
|
|
689
689
|
}, {
|
|
690
|
-
username: string;
|
|
691
690
|
email: string;
|
|
691
|
+
username: string;
|
|
692
692
|
password: string;
|
|
693
693
|
}>>["in"] ? T_7 extends _trpc_server.TRPCUnsetMarker ? void : T_7 : never : never;
|
|
694
694
|
output: {
|
package/dist/index.js
CHANGED
|
@@ -905,13 +905,13 @@ var BaseProcedureFactory = class {
|
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
if (!validCode) {
|
|
908
|
-
const checkOTP = await this.config.prisma.oTP.
|
|
909
|
-
where: { userId: user.id }
|
|
908
|
+
const checkOTP = await this.config.prisma.oTP.findFirst({
|
|
909
|
+
where: { userId: user.id, code: Number(code), expiresAt: { gte: /* @__PURE__ */ new Date() } }
|
|
910
910
|
});
|
|
911
|
-
if (checkOTP
|
|
911
|
+
if (checkOTP) {
|
|
912
912
|
validCode = true;
|
|
913
913
|
await this.config.prisma.oTP.delete({
|
|
914
|
-
where: {
|
|
914
|
+
where: { id: checkOTP.id }
|
|
915
915
|
});
|
|
916
916
|
}
|
|
917
917
|
}
|
|
@@ -1169,10 +1169,23 @@ var BaseProcedureFactory = class {
|
|
|
1169
1169
|
data: { password: hashedPassword }
|
|
1170
1170
|
});
|
|
1171
1171
|
await this.config.prisma.passwordReset.delete({ where: { id: token } });
|
|
1172
|
+
const sessionsToRevoke = await this.config.prisma.session.findMany({
|
|
1173
|
+
where: { userId: passwordReset.userId, revokedAt: null },
|
|
1174
|
+
select: { id: true, socketId: true, userId: true }
|
|
1175
|
+
});
|
|
1172
1176
|
await this.config.prisma.session.updateMany({
|
|
1173
|
-
where: { userId: passwordReset.userId },
|
|
1177
|
+
where: { userId: passwordReset.userId, revokedAt: null },
|
|
1174
1178
|
data: { revokedAt: /* @__PURE__ */ new Date() }
|
|
1175
1179
|
});
|
|
1180
|
+
for (const session of sessionsToRevoke) {
|
|
1181
|
+
if (this.config.hooks?.onSessionRevoked) {
|
|
1182
|
+
await this.config.hooks.onSessionRevoked(
|
|
1183
|
+
session.id,
|
|
1184
|
+
session.socketId,
|
|
1185
|
+
"Password reset"
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1176
1189
|
return { message: "Password updated. Please log in with your new password." };
|
|
1177
1190
|
});
|
|
1178
1191
|
}
|
|
@@ -1670,11 +1683,9 @@ var TwoFaProcedureFactory = class {
|
|
|
1670
1683
|
throw new import_server6.TRPCError({ code: "FORBIDDEN", message: "Invalid credentials." });
|
|
1671
1684
|
}
|
|
1672
1685
|
const otp = generateOtp();
|
|
1673
|
-
const
|
|
1674
|
-
await this.config.prisma.oTP.
|
|
1675
|
-
|
|
1676
|
-
update: { code: otp, expiredAt },
|
|
1677
|
-
create: { userId: user.id, code: otp, expiredAt }
|
|
1686
|
+
const expiresAt = new Date(Date.now() + this.config.tokenSettings.otpValidityMs);
|
|
1687
|
+
await this.config.prisma.oTP.create({
|
|
1688
|
+
data: { userId: user.id, code: otp, expiresAt }
|
|
1678
1689
|
});
|
|
1679
1690
|
if (this.config.emailService) {
|
|
1680
1691
|
await this.config.emailService.sendOTPEmail(user.email, otp);
|
|
@@ -1693,14 +1704,14 @@ var TwoFaProcedureFactory = class {
|
|
|
1693
1704
|
if (!user) {
|
|
1694
1705
|
throw new import_server6.TRPCError({ code: "NOT_FOUND", message: "User not found" });
|
|
1695
1706
|
}
|
|
1696
|
-
const otp = await this.config.prisma.oTP.
|
|
1697
|
-
where: { userId: user.id }
|
|
1707
|
+
const otp = await this.config.prisma.oTP.findFirst({
|
|
1708
|
+
where: { userId: user.id, code, expiresAt: { gte: /* @__PURE__ */ new Date() } }
|
|
1698
1709
|
});
|
|
1699
|
-
if (!otp
|
|
1710
|
+
if (!otp) {
|
|
1700
1711
|
throw new import_server6.TRPCError({ code: "FORBIDDEN", message: "Invalid or expired OTP" });
|
|
1701
1712
|
}
|
|
1702
1713
|
await this.config.prisma.oTP.delete({
|
|
1703
|
-
where: {
|
|
1714
|
+
where: { id: otp.id }
|
|
1704
1715
|
});
|
|
1705
1716
|
await this.config.prisma.user.update({
|
|
1706
1717
|
where: { id: user.id },
|
package/dist/index.mjs
CHANGED
|
@@ -771,13 +771,13 @@ var BaseProcedureFactory = class {
|
|
|
771
771
|
}
|
|
772
772
|
}
|
|
773
773
|
if (!validCode) {
|
|
774
|
-
const checkOTP = await this.config.prisma.oTP.
|
|
775
|
-
where: { userId: user.id }
|
|
774
|
+
const checkOTP = await this.config.prisma.oTP.findFirst({
|
|
775
|
+
where: { userId: user.id, code: Number(code), expiresAt: { gte: /* @__PURE__ */ new Date() } }
|
|
776
776
|
});
|
|
777
|
-
if (checkOTP
|
|
777
|
+
if (checkOTP) {
|
|
778
778
|
validCode = true;
|
|
779
779
|
await this.config.prisma.oTP.delete({
|
|
780
|
-
where: {
|
|
780
|
+
where: { id: checkOTP.id }
|
|
781
781
|
});
|
|
782
782
|
}
|
|
783
783
|
}
|
|
@@ -1035,10 +1035,23 @@ var BaseProcedureFactory = class {
|
|
|
1035
1035
|
data: { password: hashedPassword }
|
|
1036
1036
|
});
|
|
1037
1037
|
await this.config.prisma.passwordReset.delete({ where: { id: token } });
|
|
1038
|
+
const sessionsToRevoke = await this.config.prisma.session.findMany({
|
|
1039
|
+
where: { userId: passwordReset.userId, revokedAt: null },
|
|
1040
|
+
select: { id: true, socketId: true, userId: true }
|
|
1041
|
+
});
|
|
1038
1042
|
await this.config.prisma.session.updateMany({
|
|
1039
|
-
where: { userId: passwordReset.userId },
|
|
1043
|
+
where: { userId: passwordReset.userId, revokedAt: null },
|
|
1040
1044
|
data: { revokedAt: /* @__PURE__ */ new Date() }
|
|
1041
1045
|
});
|
|
1046
|
+
for (const session of sessionsToRevoke) {
|
|
1047
|
+
if (this.config.hooks?.onSessionRevoked) {
|
|
1048
|
+
await this.config.hooks.onSessionRevoked(
|
|
1049
|
+
session.id,
|
|
1050
|
+
session.socketId,
|
|
1051
|
+
"Password reset"
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1042
1055
|
return { message: "Password updated. Please log in with your new password." };
|
|
1043
1056
|
});
|
|
1044
1057
|
}
|
|
@@ -1536,11 +1549,9 @@ var TwoFaProcedureFactory = class {
|
|
|
1536
1549
|
throw new TRPCError6({ code: "FORBIDDEN", message: "Invalid credentials." });
|
|
1537
1550
|
}
|
|
1538
1551
|
const otp = generateOtp();
|
|
1539
|
-
const
|
|
1540
|
-
await this.config.prisma.oTP.
|
|
1541
|
-
|
|
1542
|
-
update: { code: otp, expiredAt },
|
|
1543
|
-
create: { userId: user.id, code: otp, expiredAt }
|
|
1552
|
+
const expiresAt = new Date(Date.now() + this.config.tokenSettings.otpValidityMs);
|
|
1553
|
+
await this.config.prisma.oTP.create({
|
|
1554
|
+
data: { userId: user.id, code: otp, expiresAt }
|
|
1544
1555
|
});
|
|
1545
1556
|
if (this.config.emailService) {
|
|
1546
1557
|
await this.config.emailService.sendOTPEmail(user.email, otp);
|
|
@@ -1559,14 +1570,14 @@ var TwoFaProcedureFactory = class {
|
|
|
1559
1570
|
if (!user) {
|
|
1560
1571
|
throw new TRPCError6({ code: "NOT_FOUND", message: "User not found" });
|
|
1561
1572
|
}
|
|
1562
|
-
const otp = await this.config.prisma.oTP.
|
|
1563
|
-
where: { userId: user.id }
|
|
1573
|
+
const otp = await this.config.prisma.oTP.findFirst({
|
|
1574
|
+
where: { userId: user.id, code, expiresAt: { gte: /* @__PURE__ */ new Date() } }
|
|
1564
1575
|
});
|
|
1565
|
-
if (!otp
|
|
1576
|
+
if (!otp) {
|
|
1566
1577
|
throw new TRPCError6({ code: "FORBIDDEN", message: "Invalid or expired OTP" });
|
|
1567
1578
|
}
|
|
1568
1579
|
await this.config.prisma.oTP.delete({
|
|
1569
|
-
where: {
|
|
1580
|
+
where: { id: otp.id }
|
|
1570
1581
|
});
|
|
1571
1582
|
await this.config.prisma.user.update({
|
|
1572
1583
|
where: { id: user.id },
|
package/dist/validators.d.mts
CHANGED
|
@@ -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-
|
|
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';
|
package/dist/validators.d.ts
CHANGED
|
@@ -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-
|
|
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';
|
package/package.json
CHANGED
package/prisma/schema.prisma
CHANGED
|
@@ -116,11 +116,13 @@ model PasswordReset {
|
|
|
116
116
|
// ==============================================================================
|
|
117
117
|
|
|
118
118
|
model OTP {
|
|
119
|
+
id Int @id @default(autoincrement())
|
|
119
120
|
code Int
|
|
120
|
-
|
|
121
|
-
userId Int
|
|
121
|
+
expiresAt DateTime
|
|
122
|
+
userId Int
|
|
122
123
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
123
124
|
|
|
125
|
+
@@index([userId])
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// ==============================================================================
|
|
@@ -8,12 +8,12 @@ declare const signupSchema: z.ZodObject<{
|
|
|
8
8
|
email: z.ZodString;
|
|
9
9
|
password: z.ZodEffects<z.ZodString, string, string>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
username: string;
|
|
12
11
|
email: string;
|
|
12
|
+
username: string;
|
|
13
13
|
password: string;
|
|
14
14
|
}, {
|
|
15
|
-
username: string;
|
|
16
15
|
email: string;
|
|
16
|
+
username: string;
|
|
17
17
|
password: string;
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
@@ -8,12 +8,12 @@ declare const signupSchema: z.ZodObject<{
|
|
|
8
8
|
email: z.ZodString;
|
|
9
9
|
password: z.ZodEffects<z.ZodString, string, string>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
username: string;
|
|
12
11
|
email: string;
|
|
12
|
+
username: string;
|
|
13
13
|
password: string;
|
|
14
14
|
}, {
|
|
15
|
-
username: string;
|
|
16
15
|
email: string;
|
|
16
|
+
username: string;
|
|
17
17
|
password: string;
|
|
18
18
|
}>;
|
|
19
19
|
/**
|