@@ -18,11 +18,13 @@ export class AuthService {
18
18
private _userService : UsersService ,
19
19
private _organizationService : OrganizationService ,
20
20
private _notificationService : NotificationService ,
21
- private _emailService : EmailService ,
21
+ private _emailService : EmailService
22
22
) { }
23
23
async routeAuth (
24
24
provider : Provider ,
25
25
body : CreateOrgUserDto | LoginUserDto ,
26
+ ip : string ,
27
+ userAgent : string ,
26
28
addToOrg ?: boolean | { orgId : string ; role : 'USER' | 'ADMIN' ; id : string }
27
29
) {
28
30
if ( provider === Provider . LOCAL ) {
@@ -32,7 +34,11 @@ export class AuthService {
32
34
throw new Error ( 'User already exists' ) ;
33
35
}
34
36
35
- const create = await this . _organizationService . createOrgAndUser ( body ) ;
37
+ const create = await this . _organizationService . createOrgAndUser (
38
+ body ,
39
+ ip ,
40
+ userAgent
41
+ ) ;
36
42
37
43
const addedOrg =
38
44
addToOrg && typeof addToOrg !== 'boolean'
@@ -45,7 +51,11 @@ export class AuthService {
45
51
: false ;
46
52
47
53
const obj = { addedOrg, jwt : await this . jwt ( create . users [ 0 ] . user ) } ;
48
- await this . _emailService . sendEmail ( body . email , 'Activate your account' , `Click <a href="${ process . env . FRONTEND_URL } /auth/activate/${ obj . jwt } ">here</a> to activate your account` ) ;
54
+ await this . _emailService . sendEmail (
55
+ body . email ,
56
+ 'Activate your account' ,
57
+ `Click <a href="${ process . env . FRONTEND_URL } /auth/activate/${ obj . jwt } ">here</a> to activate your account`
58
+ ) ;
49
59
return obj ;
50
60
}
51
61
@@ -62,7 +72,9 @@ export class AuthService {
62
72
63
73
const user = await this . loginOrRegisterProvider (
64
74
provider ,
65
- body as CreateOrgUserDto
75
+ body as CreateOrgUserDto ,
76
+ ip ,
77
+ userAgent
66
78
) ;
67
79
68
80
const addedOrg =
@@ -101,7 +113,9 @@ export class AuthService {
101
113
102
114
private async loginOrRegisterProvider (
103
115
provider : Provider ,
104
- body : CreateOrgUserDto
116
+ body : CreateOrgUserDto ,
117
+ ip : string ,
118
+ userAgent : string
105
119
) {
106
120
const providerInstance = ProvidersFactory . loadProvider ( provider ) ;
107
121
const providerUser = await providerInstance . getUser ( body . providerToken ) ;
@@ -118,15 +132,19 @@ export class AuthService {
118
132
return user ;
119
133
}
120
134
121
- const create = await this . _organizationService . createOrgAndUser ( {
122
- company : body . company ,
123
- email : providerUser . email ,
124
- password : '' ,
125
- provider,
126
- providerId : providerUser . id ,
127
- } ) ;
135
+ const create = await this . _organizationService . createOrgAndUser (
136
+ {
137
+ company : body . company ,
138
+ email : providerUser . email ,
139
+ password : '' ,
140
+ provider,
141
+ providerId : providerUser . id ,
142
+ } ,
143
+ ip ,
144
+ userAgent
145
+ ) ;
128
146
129
- NewsletterService . register ( providerUser . email ) ;
147
+ await NewsletterService . register ( providerUser . email ) ;
130
148
131
149
return create . users [ 0 ] . user ;
132
150
}
@@ -162,7 +180,11 @@ export class AuthService {
162
180
}
163
181
164
182
async activate ( code : string ) {
165
- const user = AuthChecker . verifyJWT ( code ) as { id : string , activated : boolean , email : string } ;
183
+ const user = AuthChecker . verifyJWT ( code ) as {
184
+ id : string ;
185
+ activated : boolean ;
186
+ email : string ;
187
+ } ;
166
188
if ( user . id && ! user . activated ) {
167
189
const getUserAgain = await this . _userService . getUserByEmail ( user . email ) ;
168
190
if ( getUserAgain . activated ) {
0 commit comments