-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
configService와 process.env
24.04.17 00:04 작성 조회수 62
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'],
});
}
이렇게 직접 환경변수를 적어주는 방법 밖에는 없을까요?
[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - Part 1 NestJS Core
process 객체를 이용해서 환경변수 불러오기
강의실 바로가기
답변을 작성해보세요.
0
답변 1