@@ -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
@@ -173,7 +174,7 @@ export class AppService {
173
174
const resetToken = this . jwtService . sign (
174
175
{ userId : user . _id . toString ( ) , email : dto . email , type : 'reset-password' } ,
175
176
{
176
- secret : process . env . JWT_SECRET ,
177
+ secret : config . auth . local . jwtSecret ,
177
178
expiresIn : '1hr' ,
178
179
} ,
179
180
) ;
@@ -206,7 +207,7 @@ export class AppService {
206
207
public async validatePasswordResetToken ( token : string ) : Promise < any > {
207
208
try {
208
209
const decoded = this . jwtService . verify ( token , {
209
- secret : process . env . JWT_SECRET ,
210
+ secret : config . auth . local . jwtSecret ,
210
211
} ) ;
211
212
const { userId, email, type } = decoded ;
212
213
if ( type !== 'reset-password' ) {
@@ -225,16 +226,16 @@ export class AppService {
225
226
}
226
227
227
228
private async sendResetEmail ( email : string , token : string ) {
228
- 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
229
230
230
231
const transporter = nodemailer . createTransport ( {
231
232
service : 'gmail' ,
232
233
host : 'smtp.gmail.com' ,
233
234
port : 465 ,
234
235
secure : true ,
235
236
auth : {
236
- user : process . env . NODEMAILER_GMAIL_USER ,
237
- pass : process . env . NODEMAILER_GMAIL_PASSWORD ,
237
+ user : config . mailer . user ,
238
+ pass : config . mailer . password ,
238
239
} ,
239
240
} ) ;
240
241
@@ -255,7 +256,7 @@ export class AppService {
255
256
public async validateAccessToken ( accessToken : string ) : Promise < any > {
256
257
try {
257
258
const decoded = this . jwtService . verify ( accessToken , {
258
- secret : process . env . JWT_SECRET ,
259
+ secret : config . auth . local . jwtSecret ,
259
260
} ) ;
260
261
return decoded ;
261
262
} catch ( error ) {
@@ -266,7 +267,7 @@ export class AppService {
266
267
public async validateRefreshToken ( refreshToken : string ) : Promise < any > {
267
268
try {
268
269
const decoded = this . jwtService . verify ( refreshToken , {
269
- secret : process . env . JWT_REFRESH_SECRET ,
270
+ secret : config . auth . local . jwtRefreshSecret ,
270
271
} ) ;
271
272
return decoded ;
272
273
} catch ( error ) {
@@ -300,7 +301,7 @@ export class AppService {
300
301
...rest ,
301
302
} ,
302
303
{
303
- secret : process . env . JWT_SECRET ,
304
+ secret : config . auth . local . jwtSecret ,
304
305
expiresIn : '1h' , // 1 hour
305
306
} ,
306
307
) ,
@@ -310,7 +311,7 @@ export class AppService {
310
311
...rest ,
311
312
} ,
312
313
{
313
- secret : process . env . JWT_REFRESH_SECRET ,
314
+ secret : config . auth . local . jwtRefreshSecret ,
314
315
expiresIn : '7d' , // 1 week
315
316
} ,
316
317
) ,
@@ -323,8 +324,8 @@ export class AppService {
323
324
}
324
325
325
326
getGoogleOAuthUrl ( ) : string {
326
- const clientId = process . env . GOOGLE_CLIENT_ID ;
327
- const redirectUri = process . env . GOOGLE_CALLBACK_URL ;
327
+ const clientId = config . auth . google . clientId ;
328
+ const redirectUri = config . auth . google . callbackUrl ;
328
329
const scope = encodeURIComponent ( 'email profile' ) ;
329
330
const responseType = 'code' ;
330
331
const state = 'secureRandomState' ;
@@ -404,7 +405,7 @@ export class AppService {
404
405
405
406
const ticket = await this . oauthClient . verifyIdToken ( {
406
407
idToken : tokens . id_token ,
407
- audience : process . env . GOOGLE_CLIENT_ID ,
408
+ audience : config . auth . google . clientId ,
408
409
} ) ;
409
410
410
411
const payload = ticket . getPayload ( ) ;
@@ -428,8 +429,8 @@ export class AppService {
428
429
}
429
430
430
431
getGithubOAuthUrl ( ) : string {
431
- const clientId = process . env . GITHUB_CLIENT_ID ;
432
- const redirectUri = process . env . GITHUB_CALLBACK_URL ;
432
+ const clientId = config . auth . github . clientId ;
433
+ const redirectUri = config . auth . github . callbackUrl ;
433
434
const scope = 'user:email' ;
434
435
435
436
const githubLoginUrl = `https://github.com/login/oauth/authorize?client_id=${ clientId } &redirect_uri=${ encodeURIComponent (
@@ -486,10 +487,10 @@ export class AppService {
486
487
private async exchangeGithubCodeForTokens ( code : string ) {
487
488
try {
488
489
const params = {
489
- client_id : process . env . GITHUB_CLIENT_ID ,
490
- client_secret : process . env . GITHUB_CLIENT_SECRET ,
490
+ client_id : config . auth . github . clientId ,
491
+ client_secret : config . auth . github . clientSecret ,
491
492
code : code ,
492
- redirect_uri : process . env . GITHUB_CALLBACK_URL ,
493
+ redirect_uri : config . auth . github . callbackUrl ,
493
494
} ;
494
495
const headers = {
495
496
Accept : 'application/json' ,
0 commit comments