@vynelix/nestjs-multi-auth 0.3.1 → 1.0.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 (196) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +309 -18
  3. package/dist/auth/auth.controller.d.ts +3 -2
  4. package/dist/auth/auth.controller.js +32 -5
  5. package/dist/auth/auth.controller.js.map +1 -1
  6. package/dist/auth/auth.module.js +116 -68
  7. package/dist/auth/auth.module.js.map +1 -1
  8. package/dist/auth/auth.service.d.ts +53 -26
  9. package/dist/auth/auth.service.js +239 -328
  10. package/dist/auth/auth.service.js.map +1 -1
  11. package/dist/auth/core/auth-mapper.d.ts +1 -1
  12. package/dist/auth/core/database-otp.provider.d.ts +12 -0
  13. package/dist/auth/core/database-otp.provider.js +122 -0
  14. package/dist/auth/core/database-otp.provider.js.map +1 -0
  15. package/dist/auth/dto/requests/magic-link.dto.d.ts +1 -0
  16. package/dist/auth/dto/requests/magic-link.dto.js +6 -0
  17. package/dist/auth/dto/requests/magic-link.dto.js.map +1 -1
  18. package/dist/auth/dto/requests/mfa.dto.d.ts +5 -1
  19. package/dist/auth/dto/requests/mfa.dto.js +29 -8
  20. package/dist/auth/dto/requests/mfa.dto.js.map +1 -1
  21. package/dist/auth/enums/identifier-type.enum.d.ts +11 -0
  22. package/dist/auth/enums/identifier-type.enum.js +17 -0
  23. package/dist/auth/enums/identifier-type.enum.js.map +1 -0
  24. package/dist/auth/enums/mfa-type.enum.d.ts +5 -0
  25. package/dist/auth/enums/mfa-type.enum.js +10 -0
  26. package/dist/auth/enums/mfa-type.enum.js.map +1 -0
  27. package/dist/auth/enums/otp-purpose.enum.d.ts +8 -0
  28. package/dist/auth/enums/otp-purpose.enum.js +13 -0
  29. package/dist/auth/enums/otp-purpose.enum.js.map +1 -0
  30. package/dist/auth/enums/session-event.enum.d.ts +7 -0
  31. package/dist/auth/enums/session-event.enum.js +12 -0
  32. package/dist/auth/enums/session-event.enum.js.map +1 -0
  33. package/dist/auth/interfaces/auth-module-options.interface.d.ts +36 -1
  34. package/dist/auth/interfaces/auth-notification-provider.interface.d.ts +7 -1
  35. package/dist/auth/interfaces/auth-otp-provider.interface.d.ts +60 -0
  36. package/dist/auth/interfaces/auth-otp-provider.interface.js +7 -0
  37. package/dist/auth/interfaces/auth-otp-provider.interface.js.map +1 -0
  38. package/dist/auth/interfaces/models.interface.d.ts +91 -0
  39. package/dist/auth/interfaces/models.interface.js +3 -0
  40. package/dist/auth/interfaces/models.interface.js.map +1 -0
  41. package/dist/auth/interfaces/oauth-strategy.interface.d.ts +2 -2
  42. package/dist/auth/interfaces/repositories.interface.d.ts +70 -0
  43. package/dist/auth/interfaces/repositories.interface.js +3 -0
  44. package/dist/auth/interfaces/repositories.interface.js.map +1 -0
  45. package/dist/auth/interfaces/repository-tokens.d.ts +7 -0
  46. package/dist/auth/interfaces/repository-tokens.js +11 -0
  47. package/dist/auth/interfaces/repository-tokens.js.map +1 -0
  48. package/dist/auth/interfaces/signup-event-body.interface.d.ts +1 -1
  49. package/dist/auth/strategies/local-auth.strategy.d.ts +3 -5
  50. package/dist/auth/strategies/local-auth.strategy.js +64 -99
  51. package/dist/auth/strategies/local-auth.strategy.js.map +1 -1
  52. package/dist/auth/strategies/oauth/apple.strategy.d.ts +4 -6
  53. package/dist/auth/strategies/oauth/apple.strategy.js +57 -70
  54. package/dist/auth/strategies/oauth/apple.strategy.js.map +1 -1
  55. package/dist/auth/strategies/oauth/facebook.strategy.d.ts +4 -6
  56. package/dist/auth/strategies/oauth/facebook.strategy.js +58 -71
  57. package/dist/auth/strategies/oauth/facebook.strategy.js.map +1 -1
  58. package/dist/auth/strategies/oauth/google.strategy.d.ts +4 -6
  59. package/dist/auth/strategies/oauth/google.strategy.js +84 -155
  60. package/dist/auth/strategies/oauth/google.strategy.js.map +1 -1
  61. package/dist/auth/strategies/oauth/oauth.strategy.d.ts +2 -2
  62. package/dist/database/prisma/prisma-auth.adapter.d.ts +11 -0
  63. package/dist/database/prisma/prisma-auth.adapter.js +64 -0
  64. package/dist/database/prisma/prisma-auth.adapter.js.map +1 -0
  65. package/dist/database/prisma/repositories/auth-identifier.repository.d.ts +16 -0
  66. package/dist/database/prisma/repositories/auth-identifier.repository.js +41 -0
  67. package/dist/database/prisma/repositories/auth-identifier.repository.js.map +1 -0
  68. package/dist/database/prisma/repositories/auth.repository.d.ts +19 -0
  69. package/dist/database/prisma/repositories/auth.repository.js +49 -0
  70. package/dist/database/prisma/repositories/auth.repository.js.map +1 -0
  71. package/dist/database/prisma/repositories/index.d.ts +7 -0
  72. package/dist/database/prisma/repositories/index.js +24 -0
  73. package/dist/database/prisma/repositories/index.js.map +1 -0
  74. package/dist/database/prisma/repositories/mfa-method.repository.d.ts +11 -0
  75. package/dist/database/prisma/repositories/mfa-method.repository.js +33 -0
  76. package/dist/database/prisma/repositories/mfa-method.repository.js.map +1 -0
  77. package/dist/database/prisma/repositories/oauth-provider.repository.d.ts +14 -0
  78. package/dist/database/prisma/repositories/oauth-provider.repository.js +39 -0
  79. package/dist/database/prisma/repositories/oauth-provider.repository.js.map +1 -0
  80. package/dist/database/prisma/repositories/otp-token.repository.d.ts +13 -0
  81. package/dist/database/prisma/repositories/otp-token.repository.js +52 -0
  82. package/dist/database/prisma/repositories/otp-token.repository.js.map +1 -0
  83. package/dist/database/prisma/repositories/session-log.repository.d.ts +12 -0
  84. package/dist/database/prisma/repositories/session-log.repository.js +42 -0
  85. package/dist/database/prisma/repositories/session-log.repository.js.map +1 -0
  86. package/dist/database/prisma/repositories/session.repository.d.ts +16 -0
  87. package/dist/database/prisma/repositories/session.repository.js +41 -0
  88. package/dist/database/prisma/repositories/session.repository.js.map +1 -0
  89. package/dist/database/typeorm/entities/auth-identify.entity.d.ts +23 -0
  90. package/dist/database/typeorm/entities/auth-identify.entity.js +61 -0
  91. package/dist/database/typeorm/entities/auth-identify.entity.js.map +1 -0
  92. package/dist/database/typeorm/entities/auth.entity.d.ts +45 -0
  93. package/dist/database/typeorm/entities/auth.entity.js +129 -0
  94. package/dist/database/typeorm/entities/auth.entity.js.map +1 -0
  95. package/dist/database/typeorm/entities/base.entity.d.ts +7 -0
  96. package/dist/database/typeorm/entities/base.entity.js +44 -0
  97. package/dist/database/typeorm/entities/base.entity.js.map +1 -0
  98. package/dist/database/typeorm/entities/entities.d.ts +7 -0
  99. package/dist/database/typeorm/entities/entities.js +18 -0
  100. package/dist/database/typeorm/entities/entities.js.map +1 -0
  101. package/dist/database/typeorm/entities/mfa-method.entity.d.ts +10 -0
  102. package/dist/database/typeorm/entities/mfa-method.entity.js +47 -0
  103. package/dist/database/typeorm/entities/mfa-method.entity.js.map +1 -0
  104. package/dist/database/typeorm/entities/oauth-provider.entity.d.ts +38 -0
  105. package/dist/database/typeorm/entities/oauth-provider.entity.js +88 -0
  106. package/dist/database/typeorm/entities/oauth-provider.entity.js.map +1 -0
  107. package/dist/database/typeorm/entities/otp-token.entity.d.ts +15 -0
  108. package/dist/database/typeorm/entities/otp-token.entity.js +53 -0
  109. package/dist/database/typeorm/entities/otp-token.entity.js.map +1 -0
  110. package/dist/database/typeorm/entities/session.entity.d.ts +21 -0
  111. package/dist/database/typeorm/entities/session.entity.js +71 -0
  112. package/dist/database/typeorm/entities/session.entity.js.map +1 -0
  113. package/dist/database/typeorm/entities/session_log.entity.d.ts +25 -0
  114. package/dist/database/typeorm/entities/session_log.entity.js +78 -0
  115. package/dist/database/typeorm/entities/session_log.entity.js.map +1 -0
  116. package/dist/database/typeorm/migrations/auth-entities.d.ts +7 -0
  117. package/dist/database/typeorm/migrations/auth-entities.js +18 -0
  118. package/dist/database/typeorm/migrations/auth-entities.js.map +1 -0
  119. package/dist/database/typeorm/migrations/auth-schema.initializer.d.ts +9 -0
  120. package/dist/database/typeorm/migrations/auth-schema.initializer.js +36 -0
  121. package/dist/database/typeorm/migrations/auth-schema.initializer.js.map +1 -0
  122. package/dist/database/typeorm/migrations/auth.migration.v1.d.ts +12 -0
  123. package/dist/database/typeorm/migrations/auth.migration.v1.js +157 -0
  124. package/dist/database/typeorm/migrations/auth.migration.v1.js.map +1 -0
  125. package/dist/database/typeorm/migrations/auth.migration.v2.d.ts +8 -0
  126. package/dist/database/typeorm/migrations/auth.migration.v2.js +23 -0
  127. package/dist/database/typeorm/migrations/auth.migration.v2.js.map +1 -0
  128. package/dist/database/typeorm/migrations/auth.migrations.d.ts +2 -0
  129. package/dist/database/typeorm/migrations/auth.migrations.js +10 -0
  130. package/dist/database/typeorm/migrations/auth.migrations.js.map +1 -0
  131. package/dist/database/typeorm/migrations/migration.service.d.ts +9 -0
  132. package/dist/database/typeorm/migrations/migration.service.js +75 -0
  133. package/dist/database/typeorm/migrations/migration.service.js.map +1 -0
  134. package/dist/database/typeorm/repositories/auth-identifier.repository.d.ts +18 -0
  135. package/dist/database/typeorm/repositories/auth-identifier.repository.js +64 -0
  136. package/dist/database/typeorm/repositories/auth-identifier.repository.js.map +1 -0
  137. package/dist/database/typeorm/repositories/auth.repository.d.ts +21 -0
  138. package/dist/database/typeorm/repositories/auth.repository.js +71 -0
  139. package/dist/database/typeorm/repositories/auth.repository.js.map +1 -0
  140. package/dist/database/typeorm/repositories/index.d.ts +7 -0
  141. package/dist/database/typeorm/repositories/index.js +24 -0
  142. package/dist/database/typeorm/repositories/index.js.map +1 -0
  143. package/dist/database/typeorm/repositories/mfa-method.repository.d.ts +13 -0
  144. package/dist/database/typeorm/repositories/mfa-method.repository.js +46 -0
  145. package/dist/database/typeorm/repositories/mfa-method.repository.js.map +1 -0
  146. package/dist/database/typeorm/repositories/oauth-provider.repository.d.ts +16 -0
  147. package/dist/database/typeorm/repositories/oauth-provider.repository.js +52 -0
  148. package/dist/database/typeorm/repositories/oauth-provider.repository.js.map +1 -0
  149. package/dist/database/typeorm/repositories/otp-token.repository.d.ts +13 -0
  150. package/dist/database/typeorm/repositories/otp-token.repository.js +52 -0
  151. package/dist/database/typeorm/repositories/otp-token.repository.js.map +1 -0
  152. package/dist/database/typeorm/repositories/session-log.repository.d.ts +12 -0
  153. package/dist/database/typeorm/repositories/session-log.repository.js +47 -0
  154. package/dist/database/typeorm/repositories/session-log.repository.js.map +1 -0
  155. package/dist/database/typeorm/repositories/session.repository.d.ts +18 -0
  156. package/dist/database/typeorm/repositories/session.repository.js +84 -0
  157. package/dist/database/typeorm/repositories/session.repository.js.map +1 -0
  158. package/dist/database/typeorm/typeorm-auth.adapter.d.ts +2 -0
  159. package/dist/database/typeorm/typeorm-auth.adapter.js +50 -0
  160. package/dist/database/typeorm/typeorm-auth.adapter.js.map +1 -0
  161. package/dist/index.d.ts +11 -9
  162. package/dist/index.js +18 -10
  163. package/dist/index.js.map +1 -1
  164. package/dist/tsconfig.tsbuildinfo +1 -1
  165. package/fix-imports.js +46 -0
  166. package/fix-syntax.js +66 -0
  167. package/package.json +22 -20
  168. package/patch-local-specs.js +52 -0
  169. package/patch-oauth-specs.js +41 -0
  170. package/patch-specs.js +36 -0
  171. package/prompts/database_adapter.md +157 -0
  172. package/prompts/otp_provider.md +292 -0
  173. package/scratch/create-prisma-repos-final.js +139 -0
  174. package/scratch/create-prisma-repos.js +280 -0
  175. package/scratch/fix-events-spec.js +12 -0
  176. package/scratch/fix-imports.js +53 -0
  177. package/scratch/fix-prisma-interfaces.js +41 -0
  178. package/scratch/fix-prisma-interfaces2.js +36 -0
  179. package/scratch/fix-prisma-interfaces3.js +26 -0
  180. package/scratch/fix-prisma.js +28 -0
  181. package/scratch/fix-test-imports.js +51 -0
  182. package/scratch/fix-tests-advanced.js +68 -0
  183. package/scratch/fix-tests-advanced2.js +23 -0
  184. package/scratch/fix-tests-concrete.js +40 -0
  185. package/scratch/fix-tests-final.js +35 -0
  186. package/scratch/fix-tests-final2.js +28 -0
  187. package/scratch/fix-tests-final3.js +26 -0
  188. package/scratch/fix-tests-methods.js +40 -0
  189. package/scratch/fix-tests-proxy.js +67 -0
  190. package/scratch/fix-tests-types.js +24 -0
  191. package/scratch/rewrite-tests.js +110 -0
  192. package/tsc_errors.txt +60 -0
  193. package/tsc_errors2.txt +93 -0
  194. package/tmp-cv-test/package-lock.json +0 -250
  195. package/tmp-cv-test/package.json +0 -17
  196. package/tmp-cv-test/test.ts +0 -11
@@ -13,21 +13,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GoogleAuthStrategy = void 0;
16
- /* eslint-disable @typescript-eslint/no-unused-vars */
17
16
  const common_1 = require("@nestjs/common");
18
- const typeorm_1 = require("typeorm");
19
- const typeorm_2 = require("@nestjs/typeorm");
20
17
  const google_auth_library_1 = require("google-auth-library");
21
- const auth_entity_1 = require("../../entities/auth.entity");
22
- const oauth_provider_entity_1 = require("../../entities/oauth-provider.entity");
23
- const auth_identify_entity_1 = require("../../entities/auth-identify.entity");
18
+ const identifier_type_enum_1 = require("../../enums/identifier-type.enum");
24
19
  const auth_module_options_interface_1 = require("../../interfaces/auth-module-options.interface");
25
20
  const crypto_1 = require("crypto");
26
21
  const auth_type_enum_1 = require("../../enums/auth-type.enum");
22
+ const repository_tokens_1 = require("../../interfaces/repository-tokens");
27
23
  let GoogleAuthStrategy = class GoogleAuthStrategy {
28
- constructor(dataSource, authRepo, oauthProviderRepo, options) {
29
- this.dataSource = dataSource;
24
+ constructor(authRepo, identifierRepo, oauthProviderRepo, options) {
30
25
  this.authRepo = authRepo;
26
+ this.identifierRepo = identifierRepo;
31
27
  this.oauthProviderRepo = oauthProviderRepo;
32
28
  this.options = options;
33
29
  this.client = new google_auth_library_1.OAuth2Client(this.options.googleClientId);
@@ -55,80 +51,51 @@ let GoogleAuthStrategy = class GoogleAuthStrategy {
55
51
  const payload = await this.verifyToken(dto.token);
56
52
  const googleId = payload.sub;
57
53
  const email = payload.email?.toLowerCase();
58
- return this.dataSource.transaction(async (manager) => {
59
- const authRepo = manager.getRepository(auth_entity_1.Auth);
60
- const oauthProviderRepo = manager.getRepository(oauth_provider_entity_1.OAuthProvider);
61
- const identifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
62
- // Check if this Google account is already linked
63
- const existingProvider = await oauthProviderRepo.findOne({
64
- where: { provider: auth_type_enum_1.OAuthProviderType.GOOGLE, providerUserId: googleId },
65
- relations: ['auth'],
66
- });
67
- if (existingProvider) {
68
- throw new common_1.BadRequestException('This Google account is already linked to a user');
69
- }
70
- // Check if email identifier is already taken
71
- if (email) {
72
- const existingIdentifier = await identifierRepo.findOne({
73
- where: { value: email, type: auth_identify_entity_1.IdentifierType.EMAIL },
74
- });
75
- if (existingIdentifier) {
76
- throw new common_1.BadRequestException('A user with this email already exists. Please login instead.');
77
- }
54
+ const existingProvider = await this.oauthProviderRepo.findByProviderUserId(auth_type_enum_1.OAuthProviderType.GOOGLE, googleId);
55
+ if (existingProvider) {
56
+ throw new common_1.BadRequestException('This Google account is already linked to a user');
57
+ }
58
+ if (email) {
59
+ const existingIdentifier = await this.identifierRepo.findByValue(email);
60
+ if (existingIdentifier) {
61
+ throw new common_1.BadRequestException('A user with this email already exists. Please login instead.');
78
62
  }
79
- const identityUid = uid || (0, crypto_1.randomUUID)();
80
- const newAuth = authRepo.create({
81
- uid: identityUid,
82
- strategy: auth_type_enum_1.AuthStrategy.OAUTH,
83
- isActive: true,
63
+ }
64
+ const identityUid = uid || (0, crypto_1.randomUUID)();
65
+ const newAuth = await this.authRepo.create({
66
+ uid: identityUid,
67
+ strategy: auth_type_enum_1.AuthStrategy.OAUTH,
68
+ isActive: true,
69
+ isVerified: this.options.forceVerificationOnGoogleSignup ? false : (payload.email_verified || false),
70
+ isPrimary: true,
71
+ createdAt: new Date(),
72
+ updatedAt: new Date(),
73
+ });
74
+ const identifiers = [];
75
+ if (email) {
76
+ identifiers.push(await this.identifierRepo.create({
77
+ auth: newAuth,
78
+ type: identifier_type_enum_1.IdentifierType.EMAIL,
79
+ value: email,
84
80
  isVerified: this.options.forceVerificationOnGoogleSignup ? false : (payload.email_verified || false),
85
- isPrimary: true,
86
- });
87
- const identifiers = [];
88
- if (email) {
89
- identifiers.push(identifierRepo.create({
90
- type: auth_identify_entity_1.IdentifierType.EMAIL,
91
- value: email,
92
- isVerified: this.options.forceVerificationOnGoogleSignup ? false : (payload.email_verified || false),
93
- source: auth_identify_entity_1.IdentifierSource.GOOGLE,
94
- verifiedBy: payload.email_verified ? 'PROVIDER' : undefined,
95
- }));
96
- }
97
- newAuth.identifiers = identifiers;
98
- const oauthProvider = oauthProviderRepo.create({
99
- provider: auth_type_enum_1.OAuthProviderType.GOOGLE,
100
- providerUserId: googleId,
101
- rawProfile: payload,
102
- displayName: payload.name,
103
- avatarUrl: payload.picture,
104
- emailVerified: payload.email_verified,
105
- expiresAt: payload.exp ? new Date(payload.exp * 1000) : undefined,
106
- });
107
- newAuth.oauthProviders = [...(newAuth.oauthProviders || []), oauthProvider];
108
- return { auth: await authRepo.save(newAuth), identifier: newAuth.identifiers?.[0] };
81
+ source: identifier_type_enum_1.IdentifierSource.GOOGLE,
82
+ verifiedBy: payload.email_verified ? 'PROVIDER' : undefined,
83
+ }));
84
+ }
85
+ newAuth.identifiers = identifiers;
86
+ const oauthProvider = await this.oauthProviderRepo.create({
87
+ auth: newAuth,
88
+ provider: auth_type_enum_1.OAuthProviderType.GOOGLE,
89
+ providerUserId: googleId,
90
+ rawProfile: payload,
91
+ displayName: payload.name,
92
+ avatarUrl: payload.picture,
93
+ emailVerified: payload.email_verified,
94
+ expiresAt: payload.exp ? new Date(payload.exp * 1000) : undefined,
109
95
  });
96
+ newAuth.oauthProviders = [oauthProvider];
97
+ return { auth: await this.authRepo.save(newAuth), identifier: newAuth.identifiers?.[0] };
110
98
  }
111
- // async login(dto: LoginDto): Promise<{ auth: Auth; identifier?: AuthIdentifier }> {
112
- // if (!dto.token) {
113
- // throw new BadRequestException('Google ID token is required');
114
- // }
115
- // const payload = await this.verifyToken(dto.token);
116
- // const googleId = payload.sub;
117
- // const oauthProvider = await this.oauthProviderRepo.findOne({
118
- // where: { provider: OAuthProviderType.GOOGLE, providerUserId: googleId },
119
- // relations: ['auth', 'auth.identifiers'],
120
- // });
121
- // if (!oauthProvider || !oauthProvider.auth) {
122
- // throw new BadRequestException('No account found linked to this Google account. Please sign up.');
123
- // }
124
- // const auth = oauthProvider.auth;
125
- // auth.lastUsedAt = new Date();
126
- // await this.authRepo.save(auth);
127
- // // Find the identifier that matches the email from Google
128
- // const email = payload.email?.toLowerCase();
129
- // const identifier = auth.identifiers?.find(id => id.value === email);
130
- // return { auth, identifier };
131
- // }
132
99
  async login(dto) {
133
100
  if (!dto.token) {
134
101
  throw new common_1.BadRequestException('Google ID token is required');
@@ -136,92 +103,54 @@ let GoogleAuthStrategy = class GoogleAuthStrategy {
136
103
  const payload = await this.verifyToken(dto.token);
137
104
  const googleId = payload.sub;
138
105
  const email = payload.email?.toLowerCase();
139
- const result = await this.dataSource.transaction(async (manager) => {
140
- const oauthRepo = manager.getRepository(oauth_provider_entity_1.OAuthProvider);
141
- const authRepo = manager.getRepository(auth_entity_1.Auth);
142
- const identifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
143
- // -------------------------
144
- // 1. Load OAuth Provider INSIDE transaction
145
- // -------------------------
146
- const oauthProvider = await oauthRepo.findOne({
147
- where: {
148
- provider: auth_type_enum_1.OAuthProviderType.GOOGLE,
149
- providerUserId: googleId,
150
- },
151
- relations: ['auth', 'auth.identifiers'],
152
- });
153
- if (!oauthProvider || !oauthProvider.auth) {
154
- throw new common_1.BadRequestException('No account found linked to this Google account. Please sign up.');
155
- }
156
- const auth = oauthProvider.auth;
157
- // -------------------------
158
- // 2. Update OAuth Provider
159
- // -------------------------
160
- oauthProvider.rawProfile = payload;
161
- oauthProvider.displayName = payload.name ?? null;
162
- oauthProvider.avatarUrl = payload.picture ?? null;
163
- oauthProvider.emailVerified = payload.email_verified ?? false;
164
- // -------------------------
165
- // 3. Update Auth
166
- // -------------------------
167
- auth.lastUsedAt = new Date();
168
- // -------------------------
169
- // 4. Handle Identifier (EMAIL)
170
- // -------------------------
171
- let identifier = null;
172
- if (email) {
173
- identifier = await identifierRepo.findOne({
174
- where: {
175
- auth: { id: auth.id },
176
- type: auth_identify_entity_1.IdentifierType.EMAIL,
177
- },
106
+ const result = await this.oauthProviderRepo.findWithAuthByProviderUserId(auth_type_enum_1.OAuthProviderType.GOOGLE, googleId);
107
+ if (!result || !result.auth) {
108
+ throw new common_1.BadRequestException('No account found linked to this Google account. Please sign up.');
109
+ }
110
+ const oauthProvider = result.provider;
111
+ const auth = result.auth;
112
+ oauthProvider.rawProfile = payload;
113
+ oauthProvider.displayName = payload.name ?? null;
114
+ oauthProvider.avatarUrl = payload.picture ?? null;
115
+ oauthProvider.emailVerified = payload.email_verified ?? false;
116
+ auth.lastUsedAt = new Date();
117
+ let identifier = null;
118
+ if (email) {
119
+ const idResult = await this.identifierRepo.findWithAuthByValue(email);
120
+ identifier = idResult?.identifier || null;
121
+ if (!identifier || identifier.auth?.id !== auth.id) {
122
+ identifier = await this.identifierRepo.create({
123
+ auth,
124
+ type: identifier_type_enum_1.IdentifierType.EMAIL,
125
+ value: email,
126
+ isVerified: false,
178
127
  });
179
- if (!identifier) {
180
- identifier = identifierRepo.create({
181
- auth,
182
- type: auth_identify_entity_1.IdentifierType.EMAIL,
183
- value: email,
184
- isVerified: false,
185
- });
186
- }
187
- // always normalize + update
188
- identifier.value = email;
189
- if (!this.options.forceVerificationOnGoogleLogin) {
190
- identifier.isVerified = payload.email_verified ?? false;
191
- }
192
- identifier.verifiedBy = payload.email_verified ? 'PROVIDER' : identifier.verifiedBy;
193
- identifier.source = auth_identify_entity_1.IdentifierSource.GOOGLE;
194
- await identifierRepo.save(identifier);
195
128
  }
196
- // -------------------------
197
- // 5. Save core entities
198
- // -------------------------
199
- await oauthRepo.save(oauthProvider);
200
- await authRepo.save(auth);
201
- return { auth, identifier };
202
- });
203
- // -------------------------
204
- // 6. Reload fresh state (important for consistency)
205
- // -------------------------
206
- const updatedAuth = await this.authRepo.findOne({
207
- where: { id: result.auth.id },
208
- relations: ['identifiers', 'oauthProviders'],
209
- });
210
- const identifier = updatedAuth?.identifiers?.find((i) => i.type === auth_identify_entity_1.IdentifierType.EMAIL && i.value === email);
129
+ identifier.value = email;
130
+ if (!this.options.forceVerificationOnGoogleLogin) {
131
+ identifier.isVerified = payload.email_verified ?? false;
132
+ }
133
+ identifier.verifiedBy = payload.email_verified ? 'PROVIDER' : identifier.verifiedBy;
134
+ identifier.source = identifier_type_enum_1.IdentifierSource.GOOGLE;
135
+ await this.identifierRepo.save(identifier);
136
+ }
137
+ await this.oauthProviderRepo.save(oauthProvider);
138
+ await this.authRepo.save(auth);
139
+ const updatedAuth = await this.authRepo.findWithIdentifiers(auth.id);
140
+ const updatedIdentifier = updatedAuth?.identifiers?.find((i) => i.type === identifier_type_enum_1.IdentifierType.EMAIL && i.value === email) || identifier;
211
141
  return {
212
- auth: updatedAuth,
213
- identifier,
142
+ auth: updatedAuth || auth,
143
+ identifier: updatedIdentifier || undefined,
214
144
  };
215
145
  }
216
146
  };
217
147
  exports.GoogleAuthStrategy = GoogleAuthStrategy;
218
148
  exports.GoogleAuthStrategy = GoogleAuthStrategy = __decorate([
219
149
  (0, common_1.Injectable)(),
220
- __param(1, (0, typeorm_2.InjectRepository)(auth_entity_1.Auth)),
221
- __param(2, (0, typeorm_2.InjectRepository)(oauth_provider_entity_1.OAuthProvider)),
150
+ __param(0, (0, common_1.Inject)(repository_tokens_1.AUTH_REPOSITORY_TOKEN)),
151
+ __param(1, (0, common_1.Inject)(repository_tokens_1.AUTH_IDENTIFIER_REPOSITORY_TOKEN)),
152
+ __param(2, (0, common_1.Inject)(repository_tokens_1.OAUTH_PROVIDER_REPOSITORY_TOKEN)),
222
153
  __param(3, (0, common_1.Inject)(auth_module_options_interface_1.AUTH_MODULE_OPTIONS)),
223
- __metadata("design:paramtypes", [typeorm_1.DataSource,
224
- typeorm_1.Repository,
225
- typeorm_1.Repository, Object])
154
+ __metadata("design:paramtypes", [Object, Object, Object, Object])
226
155
  ], GoogleAuthStrategy);
227
156
  //# sourceMappingURL=google.strategy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"google.strategy.js","sourceRoot":"","sources":["../../../../src/auth/strategies/oauth/google.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,2CAAyE;AACzE,qCAAqD;AACrD,6CAAmD;AACnD,6DAAmD;AACnD,4DAAkD;AAClD,gFAAqE;AACrE,8EAAuG;AACvG,kGAAwG;AAExG,mCAAoC;AAGpC,+DAA6E;AAGtE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAG7B,YACmB,UAAsB,EACP,QAA0B,EACjB,iBAA4C,EAChD,OAA0B;QAH9C,eAAU,GAAV,UAAU,CAAY;QACP,aAAQ,GAAR,QAAQ,CAAkB;QACjB,sBAAiB,GAAjB,iBAAiB,CAA2B;QAChD,YAAO,GAAP,OAAO,CAAmB;QAE/D,IAAI,CAAC,MAAM,GAAG,IAAI,kCAAY,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9D,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,KAAa;QACrC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7C,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;aACtC,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,4BAAmB,CAAC,8BAA8B,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,4BAAmB,CAAC,sBAAsB,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,GAAc,EAAE,GAAY;QACpD,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C,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,MAAM,iBAAiB,GAAG,WAAW,EAAE,WAAW,EAAE,IAAI,CACtD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qCAAc,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAC5D,IAAI,UAAU,CAAC;QAEhB,OAAO;YACL,IAAI,EAAE,WAAW,IAAI,IAAI;YACzB,UAAU,EAAE,iBAAiB,IAAI,SAAS;SAC3C,CAAC;IACJ,CAAC;CACF,CAAA;AAlKY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,yCAAqB,CAAC,CAAA;IAC7B,WAAA,IAAA,eAAM,EAAC,oDAAgC,CAAC,CAAA;IACxC,WAAA,IAAA,eAAM,EAAC,mDAA+B,CAAC,CAAA;IACvC,WAAA,IAAA,eAAM,EAAC,mDAAmB,CAAC,CAAA;;GAPnB,kBAAkB,CAkK9B"}
@@ -1,7 +1,7 @@
1
1
  import { SignupDto } from '../../dto/requests/signup.dto';
2
2
  import { LoginDto } from '../../dto/requests/login.dto';
3
- import { Auth } from '../../entities/auth.entity';
4
- import { AuthIdentifier } from '../../entities/auth-identify.entity';
3
+ import { Auth } from '../../interfaces/models.interface';
4
+ import { AuthIdentifier } from '../../interfaces/models.interface';
5
5
  import { GoogleAuthStrategy } from './google.strategy';
6
6
  import { FacebookAuthStrategy } from './facebook.strategy';
7
7
  import { AppleAuthStrategy } from './apple.strategy';
@@ -0,0 +1,11 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export interface PrismaAuthAdapterOptions {
3
+ /**
4
+ * The injection token for your Prisma Service.
5
+ * Default: 'PRISMA_SERVICE'
6
+ */
7
+ prismaServiceToken?: string | symbol | any;
8
+ }
9
+ export declare class PrismaAuthAdapter {
10
+ static register(options?: PrismaAuthAdapterOptions): DynamicModule;
11
+ }
@@ -0,0 +1,64 @@
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 PrismaAuthAdapter_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PrismaAuthAdapter = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const repository_tokens_1 = require("../../auth/interfaces/repository-tokens");
13
+ const repositories_1 = require("./repositories");
14
+ let PrismaAuthAdapter = PrismaAuthAdapter_1 = class PrismaAuthAdapter {
15
+ static register(options = {}) {
16
+ const prismaServiceToken = options.prismaServiceToken || 'PRISMA_SERVICE';
17
+ const aliasProvider = {
18
+ provide: 'PRISMA_SERVICE_TOKEN',
19
+ useExisting: prismaServiceToken,
20
+ };
21
+ const providers = [
22
+ aliasProvider,
23
+ {
24
+ provide: repository_tokens_1.AUTH_REPOSITORY_TOKEN,
25
+ useClass: repositories_1.PrismaAuthRepository,
26
+ },
27
+ {
28
+ provide: repository_tokens_1.AUTH_IDENTIFIER_REPOSITORY_TOKEN,
29
+ useClass: repositories_1.PrismaAuthIdentifierRepository,
30
+ },
31
+ {
32
+ provide: repository_tokens_1.SESSION_REPOSITORY_TOKEN,
33
+ useClass: repositories_1.PrismaSessionRepository,
34
+ },
35
+ {
36
+ provide: repository_tokens_1.MFA_METHOD_REPOSITORY_TOKEN,
37
+ useClass: repositories_1.PrismaMfaMethodRepository,
38
+ },
39
+ {
40
+ provide: repository_tokens_1.OAUTH_PROVIDER_REPOSITORY_TOKEN,
41
+ useClass: repositories_1.PrismaOAuthProviderRepository,
42
+ },
43
+ {
44
+ provide: repository_tokens_1.SESSION_LOG_REPOSITORY_TOKEN,
45
+ useClass: repositories_1.PrismaSessionLogRepository,
46
+ },
47
+ {
48
+ provide: repository_tokens_1.OTP_TOKEN_REPOSITORY_TOKEN,
49
+ useClass: repositories_1.PrismaOtpTokenRepository,
50
+ },
51
+ ];
52
+ return {
53
+ module: PrismaAuthAdapter_1,
54
+ providers,
55
+ exports: providers.map(p => p.provide),
56
+ };
57
+ }
58
+ };
59
+ exports.PrismaAuthAdapter = PrismaAuthAdapter;
60
+ exports.PrismaAuthAdapter = PrismaAuthAdapter = PrismaAuthAdapter_1 = __decorate([
61
+ (0, common_1.Global)(),
62
+ (0, common_1.Module)({})
63
+ ], PrismaAuthAdapter);
64
+ //# sourceMappingURL=prisma-auth.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-auth.adapter.js","sourceRoot":"","sources":["../../../src/database/prisma/prisma-auth.adapter.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,+EAQiD;AAEjD,iDAQwB;AAYjB,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAC5B,MAAM,CAAC,QAAQ,CAAC,UAAoC,EAAE;QACpD,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,gBAAgB,CAAC;QAE1E,MAAM,aAAa,GAAa;YAC9B,OAAO,EAAE,sBAAsB;YAC/B,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,MAAM,SAAS,GAAe;YAC5B,aAAa;YACb;gBACE,OAAO,EAAE,yCAAqB;gBAC9B,QAAQ,EAAE,mCAAoB;aAC/B;YACD;gBACE,OAAO,EAAE,oDAAgC;gBACzC,QAAQ,EAAE,6CAA8B;aACzC;YACD;gBACE,OAAO,EAAE,4CAAwB;gBACjC,QAAQ,EAAE,sCAAuB;aAClC;YACD;gBACE,OAAO,EAAE,+CAA2B;gBACpC,QAAQ,EAAE,wCAAyB;aACpC;YACD;gBACE,OAAO,EAAE,mDAA+B;gBACxC,QAAQ,EAAE,4CAA6B;aACxC;YACD;gBACE,OAAO,EAAE,gDAA4B;gBACrC,QAAQ,EAAE,yCAA0B;aACrC;YACD;gBACE,OAAO,EAAE,8CAA0B;gBACnC,QAAQ,EAAE,uCAAwB;aACnC;SACF,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,SAAS;YACT,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAS,CAAC,OAAO,CAAC;SAChD,CAAC;IACJ,CAAC;CACF,CAAA;AA/CY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CA+C7B"}
@@ -0,0 +1,16 @@
1
+ import { AuthIdentifierRepository } from '../../../auth/interfaces/repositories.interface';
2
+ import { AuthIdentifier as CoreAuthIdentifier, Auth as CoreAuth } from '../../../auth/interfaces/models.interface';
3
+ export declare class PrismaAuthIdentifierRepository implements AuthIdentifierRepository {
4
+ private readonly prisma;
5
+ constructor(prisma: any);
6
+ create(data: Partial<CoreAuthIdentifier>): Promise<CoreAuthIdentifier>;
7
+ findByValue(value: string): Promise<CoreAuthIdentifier | null>;
8
+ findByAuthId(authId: string): Promise<CoreAuthIdentifier[]>;
9
+ findByUidAndTypes(uid: string, types: string[]): Promise<CoreAuthIdentifier | null>;
10
+ findWithAuthByValue(value: string): Promise<{
11
+ identifier: CoreAuthIdentifier;
12
+ auth: CoreAuth;
13
+ } | null>;
14
+ save(identifier: CoreAuthIdentifier): Promise<CoreAuthIdentifier>;
15
+ markVerifiedByAuthId(authId: string): Promise<void>;
16
+ }
@@ -0,0 +1,41 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PrismaAuthIdentifierRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ let PrismaAuthIdentifierRepository = class PrismaAuthIdentifierRepository {
18
+ constructor(prisma) {
19
+ this.prisma = prisma;
20
+ }
21
+ async create(data) { return this.prisma.authIdentifier.create({ data: data }); }
22
+ async findByValue(value) { return this.prisma.authIdentifier.findUnique({ where: { value } }); }
23
+ async findByAuthId(authId) { return this.prisma.authIdentifier.findMany({ where: { authId } }); }
24
+ async findByUidAndTypes(uid, types) { return this.prisma.authIdentifier.findFirst({ where: { auth: { uid }, type: { in: types } } }); }
25
+ async findWithAuthByValue(value) {
26
+ const res = await this.prisma.authIdentifier.findUnique({ where: { value }, include: { auth: true } });
27
+ if (!res)
28
+ return null;
29
+ const { auth, ...identifier } = res;
30
+ return { identifier: identifier, auth: auth };
31
+ }
32
+ async save(identifier) { return this.prisma.authIdentifier.update({ where: { id: identifier.id }, data: identifier }); }
33
+ async markVerifiedByAuthId(authId) { await this.prisma.authIdentifier.updateMany({ where: { authId }, data: { isVerified: true } }); }
34
+ };
35
+ exports.PrismaAuthIdentifierRepository = PrismaAuthIdentifierRepository;
36
+ exports.PrismaAuthIdentifierRepository = PrismaAuthIdentifierRepository = __decorate([
37
+ (0, common_1.Injectable)(),
38
+ __param(0, (0, common_1.Inject)('PRISMA_SERVICE_TOKEN')),
39
+ __metadata("design:paramtypes", [Object])
40
+ ], PrismaAuthIdentifierRepository);
41
+ //# sourceMappingURL=auth-identifier.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-identifier.repository.js","sourceRoot":"","sources":["../../../../src/database/prisma/repositories/auth-identifier.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAK7C,IAAM,8BAA8B,GAApC,MAAM,8BAA8B;IACzC,YAA6D,MAAW;QAAX,WAAM,GAAN,MAAM,CAAK;IAAG,CAAC;IAE5E,KAAK,CAAC,MAAM,CAAC,IAAiC,IAAiC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IACjJ,KAAK,CAAC,WAAW,CAAC,KAAa,IAAwC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5I,KAAK,CAAC,YAAY,CAAC,MAAc,IAAmC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACxI,KAAK,CAAC,iBAAiB,CAAC,GAAW,EAAE,KAAe,IAAwC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAC,CAAC,CAAC,CAAC,CAAC;IAE5L,KAAK,CAAC,mBAAmB,CAAC,KAAa;QACrC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACvG,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,GAAG,CAAC;QACpC,OAAO,EAAE,UAAU,EAAE,UAAiB,EAAE,IAAI,EAAE,IAAW,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAA8B,IAAiC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;IAChL,KAAK,CAAC,oBAAoB,CAAC,MAAc,IAAmB,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;CAC9J,CAAA;AAjBY,wEAA8B;yCAA9B,8BAA8B;IAD1C,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,sBAAsB,CAAC,CAAA;;GADhC,8BAA8B,CAiB1C"}
@@ -0,0 +1,19 @@
1
+ import { AuthRepository } from '../../../auth/interfaces/repositories.interface';
2
+ import { Auth as CoreAuth } from '../../../auth/interfaces/models.interface';
3
+ import { AuthStrategy } from '../../../auth/enums/auth-type.enum';
4
+ export declare class PrismaAuthRepository implements AuthRepository {
5
+ private readonly prisma;
6
+ constructor(prisma: any);
7
+ create(data: Partial<CoreAuth>): Promise<CoreAuth>;
8
+ findById(id: string): Promise<CoreAuth | null>;
9
+ findByUid(uid: string): Promise<CoreAuth | null>;
10
+ findAllByUid(uid: string): Promise<CoreAuth[]>;
11
+ findAll(): Promise<CoreAuth[]>;
12
+ findByUidAndStrategy(uid: string, strategy: AuthStrategy): Promise<CoreAuth | null>;
13
+ findByUidAndStrategies(uid: string, strategies: AuthStrategy[]): Promise<CoreAuth | null>;
14
+ save(auth: CoreAuth): Promise<CoreAuth>;
15
+ update(id: string, data: Partial<CoreAuth>): Promise<void>;
16
+ delete(id: string): Promise<void>;
17
+ deleteByUid(uid: string): Promise<void>;
18
+ findWithIdentifiers(id: string): Promise<CoreAuth | null>;
19
+ }
@@ -0,0 +1,49 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PrismaAuthRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ let PrismaAuthRepository = class PrismaAuthRepository {
18
+ constructor(prisma) {
19
+ this.prisma = prisma;
20
+ }
21
+ async create(data) {
22
+ const { identifiers, ...rest } = data;
23
+ return this.prisma.auth.create({
24
+ data: {
25
+ ...rest,
26
+ identifiers: identifiers ? { create: identifiers } : undefined,
27
+ },
28
+ include: { identifiers: true }
29
+ });
30
+ }
31
+ async findById(id) { return this.prisma.auth.findUnique({ where: { id }, include: { identifiers: true } }); }
32
+ async findByUid(uid) { return this.prisma.auth.findUnique({ where: { uid }, include: { identifiers: true } }); }
33
+ async findAllByUid(uid) { return this.prisma.auth.findMany({ where: { uid } }); }
34
+ async findAll() { return this.prisma.auth.findMany(); }
35
+ async findByUidAndStrategy(uid, strategy) { return this.prisma.auth.findFirst({ where: { uid, strategy } }); }
36
+ async findByUidAndStrategies(uid, strategies) { return this.prisma.auth.findFirst({ where: { uid, strategy: { in: strategies } } }); }
37
+ async save(auth) { return this.prisma.auth.update({ where: { id: auth.id }, data: auth }); }
38
+ async update(id, data) { await this.prisma.auth.update({ where: { id }, data: data }); }
39
+ async delete(id) { await this.prisma.auth.delete({ where: { id } }); }
40
+ async deleteByUid(uid) { await this.prisma.auth.deleteMany({ where: { uid } }); }
41
+ async findWithIdentifiers(id) { return this.prisma.auth.findUnique({ where: { id }, include: { identifiers: true } }); }
42
+ };
43
+ exports.PrismaAuthRepository = PrismaAuthRepository;
44
+ exports.PrismaAuthRepository = PrismaAuthRepository = __decorate([
45
+ (0, common_1.Injectable)(),
46
+ __param(0, (0, common_1.Inject)('PRISMA_SERVICE_TOKEN')),
47
+ __metadata("design:paramtypes", [Object])
48
+ ], PrismaAuthRepository);
49
+ //# sourceMappingURL=auth.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.repository.js","sourceRoot":"","sources":["../../../../src/database/prisma/repositories/auth.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAM7C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,YAA6D,MAAW;QAAX,WAAM,GAAN,MAAM,CAAK;IAAG,CAAC;IAE5E,KAAK,CAAC,MAAM,CAAC,IAAuB;QAClC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE;gBACJ,GAAG,IAAI;gBACP,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE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C,CAAC;IACxL,KAAK,CAAC,IAAI,CAAC,IAAc,IAAuB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IAChI,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,IAAuB,IAAmB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IACzI,KAAK,CAAC,MAAM,CAAC,EAAU,IAAmB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7F,KAAK,CAAC,WAAW,CAAC,GAAW,IAAmB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACxG,KAAK,CAAC,mBAAmB,CAAC,EAAU,IAA8B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;CAC3J,CAAA;AAzBY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,sBAAsB,CAAC,CAAA;;GADhC,oBAAoB,CAyBhC"}
@@ -0,0 +1,7 @@
1
+ export * from './auth.repository';
2
+ export * from './auth-identifier.repository';
3
+ export * from './session.repository';
4
+ export * from './session-log.repository';
5
+ export * from './mfa-method.repository';
6
+ export * from './oauth-provider.repository';
7
+ export * from './otp-token.repository';
@@ -0,0 +1,24 @@
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("./auth.repository"), exports);
18
+ __exportStar(require("./auth-identifier.repository"), exports);
19
+ __exportStar(require("./session.repository"), exports);
20
+ __exportStar(require("./session-log.repository"), exports);
21
+ __exportStar(require("./mfa-method.repository"), exports);
22
+ __exportStar(require("./oauth-provider.repository"), exports);
23
+ __exportStar(require("./otp-token.repository"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/database/prisma/repositories/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,+DAA6C;AAC7C,uDAAqC;AACrC,2DAAyC;AACzC,0DAAwC;AACxC,8DAA4C;AAC5C,yDAAuC"}
@@ -0,0 +1,11 @@
1
+ import { MfaMethodRepository } from '../../../auth/interfaces/repositories.interface';
2
+ import { MfaMethod as CoreMfaMethod } from '../../../auth/interfaces/models.interface';
3
+ export declare class PrismaMfaMethodRepository implements MfaMethodRepository {
4
+ private readonly prisma;
5
+ constructor(prisma: any);
6
+ create(data: Partial<CoreMfaMethod>): Promise<CoreMfaMethod>;
7
+ findByUidAndType(uid: string, type: string): Promise<CoreMfaMethod | null>;
8
+ findByUidAndEnabled(uid: string): Promise<CoreMfaMethod | null>;
9
+ save(method: CoreMfaMethod): Promise<CoreMfaMethod>;
10
+ deleteByUid(uid: string): Promise<void>;
11
+ }