inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core

process 객체를 이용해서 환경변수 불러오기

configService와 process.env

288

정민교

작성한 질문수 50

0

안녕하세요 코팩님!

class 작성 시에 다른 class를 상속하여 작성하는 경우 있잖아요

nestjs/passport를 이용해서 구글 oauth 로그인을 구현하려고 합니다.

import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-google-oauth20';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor(private readonly configService: ConfigService) {
    super({
      clientID: this.configService.get('GOOGLE_CLIENT_ID'),
      clientSecret: this.configService.get('GOOGLE_CLIENT_SECRET'),
      callbackURL: 'http://localhost:3000/auth/google/callback',
      scope: ['email', 'profile'],
    });
  }

이 경우에
super() 호출 전에 this를 참조하려고 해서 에러가 발생합니다.
이런 경우에는 불가피하게 그냥

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor() {
    super({
      clientID: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      callbackURL: 'http://localhost:3000/auth/google/callback',
      scope: ['email', 'profile'],
    });
  }

이렇게 직접 환경변수를 적어주는 방법 밖에는 없을까요?

javascript typescript rest-api nestjs backend

답변 1

0

코드팩토리

안녕하세요!

그게 가장 쉬운 방법일 것 같습니다.

감사합니다!

cascade 질문

0

38

1

@types/bcrypt 설치과정이 누락된것같습니다.

0

45

1

process.env port key 에러

0

45

1

추상화

0

48

1

[공유] DTO optional 필드가 undefined로 잡혀 TypeORM 조건이 깨지는 현상

0

93

2

where 키워드가 들어가는 메서드와 아닌 메서드

0

56

1

BearerTokenGuard에서 db를 조회해서 유저 정보를 불러오는 이유?

0

69

1

app.controller app.service 는 지워도되나요?

0

69

1

@JoinColumn을 쓰는 경우와 안쓰는 경우의 차이

0

78

1

포트 3000에서 listen하는 곳까지 넘어가지 않습니다.

0

64

1

PickType 사용 시 `as const`를 꼭 사용해야 하나요?

0

102

2

socket connect 오류

0

96

2

강의를 들으면서 궁금한 점

0

97

2

DELETE 요청의 반환값은 어떤 기준으로 결정하는 게 좋을까요?

0

59

2

커리큘럼 질문

0

98

2

put 요청은 언제

0

90

3

typeorm VS prisma

0

343

2

142 강의 > 4:00 > 포스트멘 활용 관련 질문 드립니다.

0

76

2

User 데코레이터 버그 수정 전달드립니다.

0

67

1

git 주소 부탁드립니다.

0

112

2

nest g resource 명령어 에러

0

99

2

로그인 엔드포인트 관련 질문

0

84

2

yarn으로 express 다운 후 node 2_server.js 실행 안되는 경우

0

146

3

"흔히 사용되는 메서드" 강의 관련 질문입니다~

0

95

2