@@ -18,11 +18,13 @@ export class AuthService {
1818 private _userService : UsersService ,
1919 private _organizationService : OrganizationService ,
2020 private _notificationService : NotificationService ,
21- private _emailService : EmailService ,
21+ private _emailService : EmailService
2222 ) { }
2323 async routeAuth (
2424 provider : Provider ,
2525 body : CreateOrgUserDto | LoginUserDto ,
26+ ip : string ,
27+ userAgent : string ,
2628 addToOrg ?: boolean | { orgId : string ; role : 'USER' | 'ADMIN' ; id : string }
2729 ) {
2830 if ( provider === Provider . LOCAL ) {
@@ -32,7 +34,11 @@ export class AuthService {
3234 throw new Error ( 'User already exists' ) ;
3335 }
3436
35- const create = await this . _organizationService . createOrgAndUser ( body ) ;
37+ const create = await this . _organizationService . createOrgAndUser (
38+ body ,
39+ ip ,
40+ userAgent
41+ ) ;
3642
3743 const addedOrg =
3844 addToOrg && typeof addToOrg !== 'boolean'
@@ -45,7 +51,11 @@ export class AuthService {
4551 : false ;
4652
4753 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+ ) ;
4959 return obj ;
5060 }
5161
@@ -62,7 +72,9 @@ export class AuthService {
6272
6373 const user = await this . loginOrRegisterProvider (
6474 provider ,
65- body as CreateOrgUserDto
75+ body as CreateOrgUserDto ,
76+ ip ,
77+ userAgent
6678 ) ;
6779
6880 const addedOrg =
@@ -101,7 +113,9 @@ export class AuthService {
101113
102114 private async loginOrRegisterProvider (
103115 provider : Provider ,
104- body : CreateOrgUserDto
116+ body : CreateOrgUserDto ,
117+ ip : string ,
118+ userAgent : string
105119 ) {
106120 const providerInstance = ProvidersFactory . loadProvider ( provider ) ;
107121 const providerUser = await providerInstance . getUser ( body . providerToken ) ;
@@ -118,15 +132,19 @@ export class AuthService {
118132 return user ;
119133 }
120134
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+ ) ;
128146
129- NewsletterService . register ( providerUser . email ) ;
147+ await NewsletterService . register ( providerUser . email ) ;
130148
131149 return create . users [ 0 ] . user ;
132150 }
@@ -162,7 +180,11 @@ export class AuthService {
162180 }
163181
164182 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+ } ;
166188 if ( user . id && ! user . activated ) {
167189 const getUserAgain = await this . _userService . getUserByEmail ( user . email ) ;
168190 if ( getUserAgain . activated ) {
0 commit comments