@ofeklabs/horizon-auth 0.2.1 → 0.4.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.
Files changed (132) hide show
  1. package/README.md +544 -175
  2. package/dist/account/account.module.d.ts +2 -0
  3. package/dist/account/account.module.js +23 -0
  4. package/dist/account/account.module.js.map +1 -0
  5. package/dist/account/account.service.d.ts +10 -0
  6. package/dist/account/account.service.js +69 -0
  7. package/dist/account/account.service.js.map +1 -0
  8. package/dist/account/dto/deactivate-account.dto.d.ts +3 -0
  9. package/dist/account/dto/deactivate-account.dto.js +22 -0
  10. package/dist/account/dto/deactivate-account.dto.js.map +1 -0
  11. package/dist/account/dto/index.d.ts +1 -0
  12. package/dist/account/dto/index.js +18 -0
  13. package/dist/account/dto/index.js.map +1 -0
  14. package/dist/auth/auth.controller.d.ts +81 -2
  15. package/dist/auth/auth.controller.js +304 -6
  16. package/dist/auth/auth.controller.js.map +1 -1
  17. package/dist/auth/auth.module.d.ts +2 -1
  18. package/dist/auth/auth.module.js +36 -14
  19. package/dist/auth/auth.module.js.map +1 -1
  20. package/dist/auth/auth.service.d.ts +19 -2
  21. package/dist/auth/auth.service.js +85 -3
  22. package/dist/auth/auth.service.js.map +1 -1
  23. package/dist/common/exceptions/account-deactivated.exception.d.ts +4 -0
  24. package/dist/common/exceptions/account-deactivated.exception.js +13 -0
  25. package/dist/common/exceptions/account-deactivated.exception.js.map +1 -0
  26. package/dist/common/exceptions/backup-code-already-used.exception.d.ts +4 -0
  27. package/dist/common/exceptions/backup-code-already-used.exception.js +11 -0
  28. package/dist/common/exceptions/backup-code-already-used.exception.js.map +1 -0
  29. package/dist/common/exceptions/feature-disabled.exception.d.ts +4 -0
  30. package/dist/common/exceptions/feature-disabled.exception.js +11 -0
  31. package/dist/common/exceptions/feature-disabled.exception.js.map +1 -0
  32. package/dist/common/exceptions/index.d.ts +6 -0
  33. package/dist/common/exceptions/index.js +23 -0
  34. package/dist/common/exceptions/index.js.map +1 -0
  35. package/dist/common/exceptions/invalid-two-factor-code.exception.d.ts +4 -0
  36. package/dist/common/exceptions/invalid-two-factor-code.exception.js +11 -0
  37. package/dist/common/exceptions/invalid-two-factor-code.exception.js.map +1 -0
  38. package/dist/common/exceptions/social-account-already-linked.exception.d.ts +4 -0
  39. package/dist/common/exceptions/social-account-already-linked.exception.js +11 -0
  40. package/dist/common/exceptions/social-account-already-linked.exception.js.map +1 -0
  41. package/dist/common/exceptions/two-factor-required.exception.d.ts +5 -0
  42. package/dist/common/exceptions/two-factor-required.exception.js +12 -0
  43. package/dist/common/exceptions/two-factor-required.exception.js.map +1 -0
  44. package/dist/devices/device.module.d.ts +2 -0
  45. package/dist/devices/device.module.js +24 -0
  46. package/dist/devices/device.module.js.map +1 -0
  47. package/dist/devices/device.service.d.ts +48 -0
  48. package/dist/devices/device.service.js +149 -0
  49. package/dist/devices/device.service.js.map +1 -0
  50. package/dist/devices/dto/device-info.dto.d.ts +3 -0
  51. package/dist/devices/dto/device-info.dto.js +22 -0
  52. package/dist/devices/dto/device-info.dto.js.map +1 -0
  53. package/dist/devices/dto/device-response.dto.d.ts +9 -0
  54. package/dist/devices/dto/device-response.dto.js +7 -0
  55. package/dist/devices/dto/device-response.dto.js.map +1 -0
  56. package/dist/devices/dto/index.d.ts +2 -0
  57. package/dist/devices/dto/index.js +19 -0
  58. package/dist/devices/dto/index.js.map +1 -0
  59. package/dist/index.d.ts +17 -0
  60. package/dist/index.js +17 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/horizon-auth-config.interface.d.ts +29 -0
  63. package/dist/lib/horizon-auth-env.config.d.ts +3 -0
  64. package/dist/lib/horizon-auth-env.config.js +173 -0
  65. package/dist/lib/horizon-auth-env.config.js.map +1 -0
  66. package/dist/lib/horizon-auth.module.d.ts +1 -1
  67. package/dist/lib/horizon-auth.module.js +10 -8
  68. package/dist/lib/horizon-auth.module.js.map +1 -1
  69. package/dist/push-tokens/dto/index.d.ts +1 -0
  70. package/dist/push-tokens/dto/index.js +18 -0
  71. package/dist/push-tokens/dto/index.js.map +1 -0
  72. package/dist/push-tokens/dto/register-push-token.dto.d.ts +5 -0
  73. package/dist/push-tokens/dto/register-push-token.dto.js +30 -0
  74. package/dist/push-tokens/dto/register-push-token.dto.js.map +1 -0
  75. package/dist/push-tokens/push-token.module.d.ts +2 -0
  76. package/dist/push-tokens/push-token.module.js +24 -0
  77. package/dist/push-tokens/push-token.module.js.map +1 -0
  78. package/dist/push-tokens/push-token.service.d.ts +52 -0
  79. package/dist/push-tokens/push-token.service.js +129 -0
  80. package/dist/push-tokens/push-token.service.js.map +1 -0
  81. package/dist/social-auth/dto/facebook-callback.dto.d.ts +3 -0
  82. package/dist/social-auth/dto/facebook-callback.dto.js +22 -0
  83. package/dist/social-auth/dto/facebook-callback.dto.js.map +1 -0
  84. package/dist/social-auth/dto/google-callback.dto.d.ts +3 -0
  85. package/dist/social-auth/dto/google-callback.dto.js +22 -0
  86. package/dist/social-auth/dto/google-callback.dto.js.map +1 -0
  87. package/dist/social-auth/dto/index.d.ts +2 -0
  88. package/dist/social-auth/dto/index.js +19 -0
  89. package/dist/social-auth/dto/index.js.map +1 -0
  90. package/dist/social-auth/social-auth.module.d.ts +2 -0
  91. package/dist/social-auth/social-auth.module.js +25 -0
  92. package/dist/social-auth/social-auth.module.js.map +1 -0
  93. package/dist/social-auth/social-auth.service.d.ts +43 -0
  94. package/dist/social-auth/social-auth.service.js +130 -0
  95. package/dist/social-auth/social-auth.service.js.map +1 -0
  96. package/dist/social-auth/strategies/facebook.strategy.d.ts +9 -0
  97. package/dist/social-auth/strategies/facebook.strategy.js +51 -0
  98. package/dist/social-auth/strategies/facebook.strategy.js.map +1 -0
  99. package/dist/social-auth/strategies/google.strategy.d.ts +9 -0
  100. package/dist/social-auth/strategies/google.strategy.js +49 -0
  101. package/dist/social-auth/strategies/google.strategy.js.map +1 -0
  102. package/dist/tsconfig.build.tsbuildinfo +1 -1
  103. package/dist/two-factor/dto/enable-two-factor.dto.d.ts +2 -0
  104. package/dist/two-factor/dto/enable-two-factor.dto.js +7 -0
  105. package/dist/two-factor/dto/enable-two-factor.dto.js.map +1 -0
  106. package/dist/two-factor/dto/index.d.ts +2 -0
  107. package/dist/two-factor/dto/index.js +19 -0
  108. package/dist/two-factor/dto/index.js.map +1 -0
  109. package/dist/two-factor/dto/two-factor-enabled-response.dto.d.ts +3 -0
  110. package/dist/two-factor/dto/two-factor-enabled-response.dto.js +7 -0
  111. package/dist/two-factor/dto/two-factor-enabled-response.dto.js.map +1 -0
  112. package/dist/two-factor/dto/two-factor-setup-response.dto.d.ts +4 -0
  113. package/dist/two-factor/dto/two-factor-setup-response.dto.js +7 -0
  114. package/dist/two-factor/dto/two-factor-setup-response.dto.js.map +1 -0
  115. package/dist/two-factor/dto/verify-two-factor-login.dto.d.ts +3 -0
  116. package/dist/two-factor/dto/verify-two-factor-login.dto.js +22 -0
  117. package/dist/two-factor/dto/verify-two-factor-login.dto.js.map +1 -0
  118. package/dist/two-factor/dto/verify-two-factor-setup.dto.d.ts +3 -0
  119. package/dist/two-factor/dto/verify-two-factor-setup.dto.js +22 -0
  120. package/dist/two-factor/dto/verify-two-factor-setup.dto.js.map +1 -0
  121. package/dist/two-factor/two-factor.module.d.ts +2 -0
  122. package/dist/two-factor/two-factor.module.js +23 -0
  123. package/dist/two-factor/two-factor.module.js.map +1 -0
  124. package/dist/two-factor/two-factor.service.d.ts +19 -0
  125. package/dist/two-factor/two-factor.service.js +215 -0
  126. package/dist/two-factor/two-factor.service.js.map +1 -0
  127. package/dist/users/users.service.d.ts +1 -1
  128. package/dist/users/users.service.js.map +1 -1
  129. package/package.json +26 -4
  130. package/prisma/migrations/20260218105110_add_enhanced_auth_features/migration.sql +192 -0
  131. package/prisma/migrations/migration_lock.toml +3 -0
  132. package/prisma/schema.prisma +106 -13
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RegisterPushTokenDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class RegisterPushTokenDto {
15
+ }
16
+ exports.RegisterPushTokenDto = RegisterPushTokenDto;
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ __metadata("design:type", String)
20
+ ], RegisterPushTokenDto.prototype, "token", void 0);
21
+ __decorate([
22
+ (0, class_validator_1.IsEnum)(['FCM', 'APNS']),
23
+ __metadata("design:type", String)
24
+ ], RegisterPushTokenDto.prototype, "tokenType", void 0);
25
+ __decorate([
26
+ (0, class_validator_1.IsOptional)(),
27
+ (0, class_validator_1.IsString)(),
28
+ __metadata("design:type", String)
29
+ ], RegisterPushTokenDto.prototype, "deviceId", void 0);
30
+ //# sourceMappingURL=register-push-token.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-push-token.dto.js","sourceRoot":"","sources":["../../../src/push-tokens/dto/register-push-token.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA+D;AAE/D,MAAa,oBAAoB;CAUhC;AAVD,oDAUC;AARC;IADC,IAAA,0BAAQ,GAAE;;mDACG;AAGd;IADC,IAAA,wBAAM,EAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;;uDACE;AAI1B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;sDACO"}
@@ -0,0 +1,2 @@
1
+ export declare class PushTokenModule {
2
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PushTokenModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const push_token_service_1 = require("./push-token.service");
12
+ const prisma_module_1 = require("../prisma/prisma.module");
13
+ const device_module_1 = require("../devices/device.module");
14
+ let PushTokenModule = class PushTokenModule {
15
+ };
16
+ exports.PushTokenModule = PushTokenModule;
17
+ exports.PushTokenModule = PushTokenModule = __decorate([
18
+ (0, common_1.Module)({
19
+ imports: [prisma_module_1.PrismaModule, (0, common_1.forwardRef)(() => device_module_1.DeviceModule)],
20
+ providers: [push_token_service_1.PushTokenService],
21
+ exports: [push_token_service_1.PushTokenService],
22
+ })
23
+ ], PushTokenModule);
24
+ //# sourceMappingURL=push-token.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-token.module.js","sourceRoot":"","sources":["../../src/push-tokens/push-token.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AACpD,6DAAwD;AACxD,2DAAuD;AACvD,4DAAwD;AAOjD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,4BAAY,CAAC,CAAC;QACvD,SAAS,EAAE,CAAC,qCAAgB,CAAC;QAC7B,OAAO,EAAE,CAAC,qCAAgB,CAAC;KAC5B,CAAC;GACW,eAAe,CAAG"}
@@ -0,0 +1,52 @@
1
+ import { PrismaService } from '../prisma/prisma.service';
2
+ export interface PushTokenData {
3
+ userId: string;
4
+ deviceId: string;
5
+ token: string;
6
+ tokenType: 'FCM' | 'APNS';
7
+ }
8
+ export declare class PushTokenService {
9
+ private readonly prisma;
10
+ constructor(prisma: PrismaService);
11
+ registerPushToken(data: PushTokenData): Promise<{
12
+ id: string;
13
+ createdAt: Date;
14
+ updatedAt: Date;
15
+ userId: string;
16
+ token: string;
17
+ deviceId: string;
18
+ tokenType: string;
19
+ active: boolean;
20
+ }>;
21
+ updatePushToken(tokenId: string, newToken: string): Promise<{
22
+ id: string;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ userId: string;
26
+ token: string;
27
+ deviceId: string;
28
+ tokenType: string;
29
+ active: boolean;
30
+ }>;
31
+ revokePushToken(tokenId: string): Promise<void>;
32
+ getUserPushTokens(userId: string): Promise<({
33
+ device: {
34
+ id: string;
35
+ deviceName: string | null;
36
+ deviceType: string | null;
37
+ os: string | null;
38
+ browser: string | null;
39
+ };
40
+ } & {
41
+ id: string;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ userId: string;
45
+ token: string;
46
+ deviceId: string;
47
+ tokenType: string;
48
+ active: boolean;
49
+ })[]>;
50
+ revokeDevicePushTokens(deviceId: string): Promise<void>;
51
+ getActiveTokensForUser(userId: string): Promise<string[]>;
52
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PushTokenService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const prisma_service_1 = require("../prisma/prisma.service");
15
+ let PushTokenService = class PushTokenService {
16
+ constructor(prisma) {
17
+ this.prisma = prisma;
18
+ }
19
+ async registerPushToken(data) {
20
+ const existingToken = await this.prisma.pushToken.findUnique({
21
+ where: { token: data.token },
22
+ });
23
+ if (existingToken) {
24
+ return this.prisma.pushToken.update({
25
+ where: { id: existingToken.id },
26
+ data: {
27
+ userId: data.userId,
28
+ deviceId: data.deviceId,
29
+ tokenType: data.tokenType,
30
+ active: true,
31
+ },
32
+ });
33
+ }
34
+ const deviceToken = await this.prisma.pushToken.findFirst({
35
+ where: {
36
+ deviceId: data.deviceId,
37
+ tokenType: data.tokenType,
38
+ active: true,
39
+ },
40
+ });
41
+ if (deviceToken) {
42
+ await this.prisma.pushToken.update({
43
+ where: { id: deviceToken.id },
44
+ data: { active: false },
45
+ });
46
+ }
47
+ return this.prisma.pushToken.create({
48
+ data: {
49
+ userId: data.userId,
50
+ deviceId: data.deviceId,
51
+ token: data.token,
52
+ tokenType: data.tokenType,
53
+ active: true,
54
+ },
55
+ });
56
+ }
57
+ async updatePushToken(tokenId, newToken) {
58
+ const existingToken = await this.prisma.pushToken.findUnique({
59
+ where: { id: tokenId },
60
+ });
61
+ if (!existingToken) {
62
+ throw new common_1.NotFoundException('Push token not found');
63
+ }
64
+ return this.prisma.pushToken.update({
65
+ where: { id: tokenId },
66
+ data: {
67
+ token: newToken,
68
+ active: true,
69
+ },
70
+ });
71
+ }
72
+ async revokePushToken(tokenId) {
73
+ await this.prisma.pushToken.update({
74
+ where: { id: tokenId },
75
+ data: { active: false },
76
+ });
77
+ }
78
+ async getUserPushTokens(userId) {
79
+ return this.prisma.pushToken.findMany({
80
+ where: {
81
+ userId,
82
+ active: true,
83
+ },
84
+ include: {
85
+ device: {
86
+ select: {
87
+ id: true,
88
+ deviceName: true,
89
+ deviceType: true,
90
+ os: true,
91
+ browser: true,
92
+ },
93
+ },
94
+ },
95
+ orderBy: {
96
+ createdAt: 'desc',
97
+ },
98
+ });
99
+ }
100
+ async revokeDevicePushTokens(deviceId) {
101
+ await this.prisma.pushToken.updateMany({
102
+ where: {
103
+ deviceId,
104
+ active: true,
105
+ },
106
+ data: {
107
+ active: false,
108
+ },
109
+ });
110
+ }
111
+ async getActiveTokensForUser(userId) {
112
+ const tokens = await this.prisma.pushToken.findMany({
113
+ where: {
114
+ userId,
115
+ active: true,
116
+ },
117
+ select: {
118
+ token: true,
119
+ },
120
+ });
121
+ return tokens.map((t) => t.token);
122
+ }
123
+ };
124
+ exports.PushTokenService = PushTokenService;
125
+ exports.PushTokenService = PushTokenService = __decorate([
126
+ (0, common_1.Injectable)(),
127
+ __metadata("design:paramtypes", [prisma_service_1.PrismaService])
128
+ ], PushTokenService);
129
+ //# sourceMappingURL=push-token.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-token.service.js","sourceRoot":"","sources":["../../src/push-tokens/push-token.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+D;AAC/D,6DAAyD;AAUlD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAOtD,KAAK,CAAC,iBAAiB,CAAC,IAAmB;QAEzC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;YAC3D,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;SAC7B,CAAC,CAAC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L,CAAC;IAOD,KAAK,CAAC,sBAAsB,CAAC,MAAc;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;YAClD,KAAK,EAAE;gBACL,MAAM;gBACN,MAAM,EAAE,IAAI;aACb;YACD,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI;aACZ;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AA1JY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,gBAAgB,CA0J5B"}
@@ -0,0 +1,3 @@
1
+ export declare class FacebookCallbackDto {
2
+ code: string;
3
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FacebookCallbackDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class FacebookCallbackDto {
15
+ }
16
+ exports.FacebookCallbackDto = FacebookCallbackDto;
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ (0, class_validator_1.IsNotEmpty)(),
20
+ __metadata("design:type", String)
21
+ ], FacebookCallbackDto.prototype, "code", void 0);
22
+ //# sourceMappingURL=facebook-callback.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook-callback.dto.js","sourceRoot":"","sources":["../../../src/social-auth/dto/facebook-callback.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,mBAAmB;CAI/B;AAJD,kDAIC;AADC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;iDACA"}
@@ -0,0 +1,3 @@
1
+ export declare class GoogleCallbackDto {
2
+ code: string;
3
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GoogleCallbackDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class GoogleCallbackDto {
15
+ }
16
+ exports.GoogleCallbackDto = GoogleCallbackDto;
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ (0, class_validator_1.IsNotEmpty)(),
20
+ __metadata("design:type", String)
21
+ ], GoogleCallbackDto.prototype, "code", void 0);
22
+ //# sourceMappingURL=google-callback.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-callback.dto.js","sourceRoot":"","sources":["../../../src/social-auth/dto/google-callback.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,iBAAiB;CAI7B;AAJD,8CAIC;AADC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;+CACA"}
@@ -0,0 +1,2 @@
1
+ export * from './google-callback.dto';
2
+ export * from './facebook-callback.dto';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./google-callback.dto"), exports);
18
+ __exportStar(require("./facebook-callback.dto"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/social-auth/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,0DAAwC"}
@@ -0,0 +1,2 @@
1
+ export declare class SocialAuthModule {
2
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SocialAuthModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const social_auth_service_1 = require("./social-auth.service");
12
+ const prisma_module_1 = require("../prisma/prisma.module");
13
+ const users_module_1 = require("../users/users.module");
14
+ const token_service_1 = require("../auth/services/token.service");
15
+ let SocialAuthModule = class SocialAuthModule {
16
+ };
17
+ exports.SocialAuthModule = SocialAuthModule;
18
+ exports.SocialAuthModule = SocialAuthModule = __decorate([
19
+ (0, common_1.Module)({
20
+ imports: [prisma_module_1.PrismaModule, users_module_1.UsersModule],
21
+ providers: [social_auth_service_1.SocialAuthService, token_service_1.TokenService],
22
+ exports: [social_auth_service_1.SocialAuthService],
23
+ })
24
+ ], SocialAuthModule);
25
+ //# sourceMappingURL=social-auth.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"social-auth.module.js","sourceRoot":"","sources":["../../src/social-auth/social-auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA0D;AAC1D,2DAAuD;AACvD,wDAAoD;AACpD,kEAA8D;AAOvD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAL5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,0BAAW,CAAC;QACpC,SAAS,EAAE,CAAC,uCAAiB,EAAE,4BAAY,CAAC;QAC5C,OAAO,EAAE,CAAC,uCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"}
@@ -0,0 +1,43 @@
1
+ import { PrismaService } from '../prisma/prisma.service';
2
+ import { UsersService } from '../users/users.service';
3
+ import { TokenService } from '../auth/services/token.service';
4
+ export interface SocialProfile {
5
+ provider: 'google' | 'facebook';
6
+ providerId: string;
7
+ email: string;
8
+ displayName?: string;
9
+ profileData?: any;
10
+ }
11
+ export interface AuthResponse {
12
+ user: any;
13
+ accessToken: string;
14
+ refreshToken: string;
15
+ }
16
+ export declare class SocialAuthService {
17
+ private readonly prisma;
18
+ private readonly usersService;
19
+ private readonly tokenService;
20
+ constructor(prisma: PrismaService, usersService: UsersService, tokenService: TokenService);
21
+ authenticateWithGoogle(profile: SocialProfile): Promise<AuthResponse>;
22
+ authenticateWithFacebook(profile: SocialProfile): Promise<AuthResponse>;
23
+ private authenticateWithSocialProvider;
24
+ linkSocialAccount(userId: string, provider: string, profile: SocialProfile): Promise<void>;
25
+ findUserBySocialAccount(provider: string, providerId: string): Promise<{
26
+ email: string;
27
+ id: string;
28
+ fullName: string | null;
29
+ passwordHash: string | null;
30
+ emailVerified: boolean;
31
+ emailVerifyToken: string | null;
32
+ resetToken: string | null;
33
+ resetTokenExpiry: Date | null;
34
+ tenantId: string;
35
+ roles: string[];
36
+ isActive: boolean;
37
+ deactivationReason: string | null;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ } | null>;
41
+ private createUserFromSocialProfile;
42
+ private generateAuthResponse;
43
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SocialAuthService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const prisma_service_1 = require("../prisma/prisma.service");
15
+ const users_service_1 = require("../users/users.service");
16
+ const token_service_1 = require("../auth/services/token.service");
17
+ const exceptions_1 = require("../common/exceptions");
18
+ let SocialAuthService = class SocialAuthService {
19
+ constructor(prisma, usersService, tokenService) {
20
+ this.prisma = prisma;
21
+ this.usersService = usersService;
22
+ this.tokenService = tokenService;
23
+ }
24
+ async authenticateWithGoogle(profile) {
25
+ return this.authenticateWithSocialProvider(profile);
26
+ }
27
+ async authenticateWithFacebook(profile) {
28
+ return this.authenticateWithSocialProvider(profile);
29
+ }
30
+ async authenticateWithSocialProvider(profile) {
31
+ let user = await this.findUserBySocialAccount(profile.provider, profile.providerId);
32
+ if (user) {
33
+ return this.generateAuthResponse(user);
34
+ }
35
+ const existingUser = await this.usersService.findByEmail(profile.email);
36
+ if (existingUser) {
37
+ await this.linkSocialAccount(existingUser.id, profile.provider, profile);
38
+ return this.generateAuthResponse(existingUser);
39
+ }
40
+ user = await this.createUserFromSocialProfile(profile);
41
+ return this.generateAuthResponse(user);
42
+ }
43
+ async linkSocialAccount(userId, provider, profile) {
44
+ const existingLink = await this.prisma.socialAccount.findUnique({
45
+ where: {
46
+ provider_providerId: {
47
+ provider,
48
+ providerId: profile.providerId,
49
+ },
50
+ },
51
+ });
52
+ if (existingLink && existingLink.userId !== userId) {
53
+ throw new exceptions_1.SocialAccountAlreadyLinkedException(provider);
54
+ }
55
+ if (existingLink) {
56
+ await this.prisma.socialAccount.update({
57
+ where: { id: existingLink.id },
58
+ data: {
59
+ email: profile.email,
60
+ displayName: profile.displayName,
61
+ profileData: profile.profileData,
62
+ },
63
+ });
64
+ return;
65
+ }
66
+ await this.prisma.socialAccount.create({
67
+ data: {
68
+ userId,
69
+ provider,
70
+ providerId: profile.providerId,
71
+ email: profile.email,
72
+ displayName: profile.displayName,
73
+ profileData: profile.profileData,
74
+ },
75
+ });
76
+ }
77
+ async findUserBySocialAccount(provider, providerId) {
78
+ const socialAccount = await this.prisma.socialAccount.findUnique({
79
+ where: {
80
+ provider_providerId: {
81
+ provider,
82
+ providerId,
83
+ },
84
+ },
85
+ include: {
86
+ user: true,
87
+ },
88
+ });
89
+ return socialAccount?.user || null;
90
+ }
91
+ async createUserFromSocialProfile(profile) {
92
+ const user = await this.usersService.create(profile.email, null);
93
+ if (profile.displayName) {
94
+ await this.usersService.update(user.id, { fullName: profile.displayName });
95
+ }
96
+ await this.linkSocialAccount(user.id, profile.provider, profile);
97
+ return user;
98
+ }
99
+ async generateAuthResponse(user) {
100
+ const accessToken = this.tokenService.generateAccessToken({
101
+ sub: user.id,
102
+ email: user.email,
103
+ tenantId: user.tenantId,
104
+ roles: user.roles,
105
+ });
106
+ const { token: refreshToken } = this.tokenService.generateRefreshTokenJWT(user.id);
107
+ const hashedToken = this.tokenService.hashToken(refreshToken);
108
+ const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
109
+ await this.prisma.refreshToken.create({
110
+ data: {
111
+ hashedToken,
112
+ userId: user.id,
113
+ expiresAt,
114
+ },
115
+ });
116
+ return {
117
+ user: this.usersService.toSafeUser(user),
118
+ accessToken,
119
+ refreshToken,
120
+ };
121
+ }
122
+ };
123
+ exports.SocialAuthService = SocialAuthService;
124
+ exports.SocialAuthService = SocialAuthService = __decorate([
125
+ (0, common_1.Injectable)(),
126
+ __metadata("design:paramtypes", [prisma_service_1.PrismaService,
127
+ users_service_1.UsersService,
128
+ token_service_1.TokenService])
129
+ ], SocialAuthService);
130
+ //# sourceMappingURL=social-auth.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"social-auth.service.js","sourceRoot":"","sources":["../../src/social-auth/social-auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmE;AACnE,6DAAyD;AACzD,0DAAsD;AACtD,kEAA8D;AAC9D,qDAA2E;AAiBpE,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,MAAqB,EACrB,Y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;YACxC,WAAW;YACX,YAAY;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AApLY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGgB,8BAAa;QACP,4BAAY;QACZ,4BAAY;GAJlC,iBAAiB,CAoL7B"}
@@ -0,0 +1,9 @@
1
+ import { Strategy, Profile } from 'passport-facebook';
2
+ import { SocialAuthService } from '../social-auth.service';
3
+ declare const FacebookStrategy_base: new (...args: any[]) => Strategy;
4
+ export declare class FacebookStrategy extends FacebookStrategy_base {
5
+ private readonly socialAuthService;
6
+ constructor(socialAuthService: SocialAuthService, clientID: string, clientSecret: string, callbackURL: string);
7
+ validate(accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void): Promise<any>;
8
+ }
9
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FacebookStrategy = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const passport_1 = require("@nestjs/passport");
15
+ const passport_facebook_1 = require("passport-facebook");
16
+ const social_auth_service_1 = require("../social-auth.service");
17
+ let FacebookStrategy = class FacebookStrategy extends (0, passport_1.PassportStrategy)(passport_facebook_1.Strategy, 'facebook') {
18
+ constructor(socialAuthService, clientID, clientSecret, callbackURL) {
19
+ super({
20
+ clientID,
21
+ clientSecret,
22
+ callbackURL,
23
+ profileFields: ['id', 'emails', 'name'],
24
+ });
25
+ this.socialAuthService = socialAuthService;
26
+ }
27
+ async validate(accessToken, refreshToken, profile, done) {
28
+ try {
29
+ const email = profile.emails?.[0]?.value;
30
+ const displayName = `${profile.name?.givenName || ''} ${profile.name?.familyName || ''}`.trim();
31
+ const socialProfile = {
32
+ provider: 'facebook',
33
+ providerId: profile.id,
34
+ email: email || '',
35
+ displayName,
36
+ profileData: profile,
37
+ };
38
+ const user = await this.socialAuthService.authenticateWithFacebook(socialProfile);
39
+ done(null, user);
40
+ }
41
+ catch (error) {
42
+ done(error, false);
43
+ }
44
+ }
45
+ };
46
+ exports.FacebookStrategy = FacebookStrategy;
47
+ exports.FacebookStrategy = FacebookStrategy = __decorate([
48
+ (0, common_1.Injectable)(),
49
+ __metadata("design:paramtypes", [social_auth_service_1.SocialAuthService, String, String, String])
50
+ ], FacebookStrategy);
51
+ //# sourceMappingURL=facebook.strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook.strategy.js","sourceRoot":"","sources":["../../../src/social-auth/strategies/facebook.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAoD;AACpD,yDAAsD;AACtD,gEAA2D;AAGpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,IAAA,2BAAgB,EAAC,4BAAQ,EAAE,UAAU,CAAC;IAC1E,YACmB,iBAAoC,EACrD,QAAgB,EAChB,YAAoB,EACpB,WAAmB;QAEnB,KAAK,CAAC;YACJ,QAAQ;YACR,YAAY;YACZ,WAAW;YACX,aAAa,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC;SACxC,CAAC,CAAC;QAVc,sBAAiB,GAAjB,iBAAiB,CAAmB;IAWvD,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,WAAmB,EACnB,YAAoB,EACpB,OAAgB,EAChB,IAAsC;QAEtC,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;YACzC,MAAM,WAAW,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,SAAS,IAAI,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;YAEhG,MAAM,aAAa,GAAG;gBACpB,QAAQ,EAAE,UAAmB;gBAC7B,UAAU,EAAE,OAAO,CAAC,EAAE;gBACtB,KAAK,EAAE,KAAK,IAAI,EAAE;gBAClB,WAAW;gBACX,WAAW,EAAE,OAAO;aACrB,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;YAClF,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAA;AAvCY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAG2B,uCAAiB;GAF5C,gBAAgB,CAuC5B"}
@@ -0,0 +1,9 @@
1
+ import { Strategy, VerifyCallback } from 'passport-google-oauth20';
2
+ import { SocialAuthService } from '../social-auth.service';
3
+ declare const GoogleStrategy_base: new (...args: any[]) => Strategy;
4
+ export declare class GoogleStrategy extends GoogleStrategy_base {
5
+ private readonly socialAuthService;
6
+ constructor(socialAuthService: SocialAuthService, clientID: string, clientSecret: string, callbackURL: string);
7
+ validate(accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): Promise<any>;
8
+ }
9
+ export {};