@@ -17,6 +17,7 @@ import axios, { AxiosResponse } from 'axios';
17
17
import { Token , TokenPayload } from './interfaces' ;
18
18
import { AccountProvider } from './constants/account-provider.enum' ;
19
19
import * as nodemailer from 'nodemailer' ;
20
+ import { config } from 'src/configs' ;
20
21
21
22
const SALT_ROUNDS = 10 ;
22
23
@@ -30,9 +31,9 @@ export class AppService {
30
31
@Inject ( 'USER_SERVICE' ) private readonly userClient : ClientProxy ,
31
32
) {
32
33
this . oauthClient = new OAuth2Client ( {
33
- clientId : process . env . GOOGLE_CLIENT_ID ,
34
- clientSecret : process . env . GOOGLE_CLIENT_SECRET ,
35
- redirectUri : process . env . GOOGLE_CALLBACK_URL ,
34
+ clientId : config . auth . google . clientId ,
35
+ clientSecret : config . auth . google . clientSecret ,
36
+ redirectUri : config . auth . google . callbackUrl ,
36
37
} ) ;
37
38
}
38
39
@@ -154,7 +155,9 @@ export class AppService {
154
155
}
155
156
}
156
157
157
- public async generateResetPasswordRequest ( dto : ResetPasswordRequestDto ) : Promise < boolean > {
158
+ public async generateResetPasswordRequest (
159
+ dto : ResetPasswordRequestDto ,
160
+ ) : Promise < boolean > {
158
161
const user = await firstValueFrom (
159
162
this . userClient . send (
160
163
{
@@ -171,7 +174,7 @@ export class AppService {
171
174
const resetToken = this . jwtService . sign (
172
175
{ userId : user . _id . toString ( ) , email : dto . email , type : 'reset-password' } ,
173
176
{
174
- secret : process . env . JWT_SECRET ,
177
+ secret : config . auth . local . jwtSecret ,
175
178
expiresIn : '1hr' ,
176
179
} ,
177
180
) ;
@@ -204,7 +207,7 @@ export class AppService {
204
207
public async validatePasswordResetToken ( token : string ) : Promise < any > {
205
208
try {
206
209
const decoded = this . jwtService . verify ( token , {
207
- secret : process . env . JWT_SECRET ,
210
+ secret : config . auth . local . jwtSecret ,
208
211
} ) ;
209
212
const { userId, email, type } = decoded ;
210
213
if ( type !== 'reset-password' ) {
@@ -223,16 +226,16 @@ export class AppService {
223
226
}
224
227
225
228
private async sendResetEmail ( email : string , token : string ) {
226
- const resetUrl = `${ process . env . FRONTEND_URL } /reset-password?token=${ token } ` ; // To change next time
229
+ const resetUrl = `${ config . frontendUrl } /reset-password?token=${ token } ` ; // To change next time
227
230
228
231
const transporter = nodemailer . createTransport ( {
229
232
service : 'gmail' ,
230
233
host : 'smtp.gmail.com' ,
231
234
port : 465 ,
232
235
secure : true ,
233
236
auth : {
234
- user : process . env . NODEMAILER_GMAIL_USER ,
235
- pass : process . env . NODEMAILER_GMAIL_PASSWORD ,
237
+ user : config . mailer . user ,
238
+ pass : config . mailer . password ,
236
239
} ,
237
240
} ) ;
238
241
@@ -253,7 +256,7 @@ export class AppService {
253
256
public async validateAccessToken ( accessToken : string ) : Promise < any > {
254
257
try {
255
258
const decoded = this . jwtService . verify ( accessToken , {
256
- secret : process . env . JWT_SECRET ,
259
+ secret : config . auth . local . jwtSecret ,
257
260
} ) ;
258
261
return decoded ;
259
262
} catch ( error ) {
@@ -264,7 +267,7 @@ export class AppService {
264
267
public async validateRefreshToken ( refreshToken : string ) : Promise < any > {
265
268
try {
266
269
const decoded = this . jwtService . verify ( refreshToken , {
267
- secret : process . env . JWT_REFRESH_SECRET ,
270
+ secret : config . auth . local . jwtRefreshSecret ,
268
271
} ) ;
269
272
return decoded ;
270
273
} catch ( error ) {
@@ -293,13 +296,13 @@ export class AppService {
293
296
294
297
const [ accessToken , refreshToken ] = await Promise . all ( [
295
298
this . jwtService . signAsync (
296
- {
297
- sub : id ,
298
- ...rest ,
299
- } ,
300
- {
301
- secret : process . env . JWT_SECRET ,
302
- expiresIn : '1h' , // 1 hour
299
+ {
300
+ sub : id ,
301
+ ...rest ,
302
+ } ,
303
+ {
304
+ secret : config . auth . local . jwtSecret ,
305
+ expiresIn : '1h' , // 1 hour
303
306
} ,
304
307
) ,
305
308
this . jwtService . signAsync (
@@ -308,7 +311,7 @@ export class AppService {
308
311
...rest ,
309
312
} ,
310
313
{
311
- secret : process . env . JWT_REFRESH_SECRET ,
314
+ secret : config . auth . local . jwtRefreshSecret ,
312
315
expiresIn : '7d' , // 1 week
313
316
} ,
314
317
) ,
@@ -321,8 +324,8 @@ export class AppService {
321
324
}
322
325
323
326
getGoogleOAuthUrl ( ) : string {
324
- const clientId = process . env . GOOGLE_CLIENT_ID ;
325
- const redirectUri = process . env . GOOGLE_CALLBACK_URL ;
327
+ const clientId = config . auth . google . clientId ;
328
+ const redirectUri = config . auth . google . callbackUrl ;
326
329
const scope = encodeURIComponent ( 'email profile' ) ;
327
330
const responseType = 'code' ;
328
331
const state = 'secureRandomState' ;
@@ -402,7 +405,7 @@ export class AppService {
402
405
403
406
const ticket = await this . oauthClient . verifyIdToken ( {
404
407
idToken : tokens . id_token ,
405
- audience : process . env . GOOGLE_CLIENT_ID ,
408
+ audience : config . auth . google . clientId ,
406
409
} ) ;
407
410
408
411
const payload = ticket . getPayload ( ) ;
@@ -426,8 +429,8 @@ export class AppService {
426
429
}
427
430
428
431
getGithubOAuthUrl ( ) : string {
429
- const clientId = process . env . GITHUB_CLIENT_ID ;
430
- const redirectUri = process . env . GITHUB_CALLBACK_URL ;
432
+ const clientId = config . auth . github . clientId ;
433
+ const redirectUri = config . auth . github . callbackUrl ;
431
434
const scope = 'user:email' ;
432
435
433
436
const githubLoginUrl = `https://github.com/login/oauth/authorize?client_id=${ clientId } &redirect_uri=${ encodeURIComponent (
@@ -484,10 +487,10 @@ export class AppService {
484
487
private async exchangeGithubCodeForTokens ( code : string ) {
485
488
try {
486
489
const params = {
487
- client_id : process . env . GITHUB_CLIENT_ID ,
488
- client_secret : process . env . GITHUB_CLIENT_SECRET ,
490
+ client_id : config . auth . github . clientId ,
491
+ client_secret : config . auth . github . clientSecret ,
489
492
code : code ,
490
- redirect_uri : process . env . GITHUB_CALLBACK_URL ,
493
+ redirect_uri : config . auth . github . callbackUrl ,
491
494
} ;
492
495
const headers = {
493
496
Accept : 'application/json' ,
0 commit comments