• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

configService와 process.env

24.04.17 00:04 작성 조회수 60

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'],
    });
  }

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

답변 1

답변을 작성해보세요.

0

안녕하세요!

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

감사합니다!