인프런 커뮤니티 질문&답변

반가우면반갑다고해님의 프로필 이미지

작성한 질문수

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

소셜 로그인 리팩토링

그래프큐엘로 구글 로그인 질문있습니다.

해결된 질문

24.07.17 02:21 작성

·

98

0

 현재 아래와 같은 에러를 마주쳤습니다.

my-server_1    | TypeError: res.setHeader is not a function
my-server_1    |     at JwtGoogleStrategy.strategy.redirect (/myFolder/node_modules/passport/lib/middleware/authenticate.js:340:13)
my-server_1    |     at stored (/myFolder/node_modules/passport-oauth2/lib/strategy.js:285:14)
my-server_1    |     at NullStore.store (/myFolder/node_modules/passport-oauth2/lib/state/null.js:5:3)
my-server_1    |     at JwtGoogleStrategy.OAuth2Strategy.authenticate (/myFolder/node_modules/passport-oauth2/lib/strategy.js:297:28)
my-server_1    |     at attempt (/myFolder/node_modules/passport/lib/middleware/authenticate.js:378:16)
my-server_1    |     at authenticate (/myFolder/node_modules/passport/lib/middleware/authenticate.js:379:7)
my-server_1    |     at /myFolder/node_modules/@nestjs/passport/dist/auth.guard.js:88:3
my-server_1    |     at new Promise (<anonymous>)
my-server_1    |     at /myFolder/node_modules/@nestjs/passport/dist/auth.guard.js:80:83
my-server_1    |     at GqlAuthGuard.canActivate (/myFolder/node_modules/@nestjs/passport/dist/auth.guard.js:44:32)

제 코드는 다음과 같습니다.

  • auth.resulver.ts 파일의 일부분입니다.

 @UseGuards(GqlAuthGuard('google'))
  @Mutation(() => String)
  loginGoogle(
    @Context() context: IContext, //
  ): void {
    console.log('context::', context);
  }

  • 그래프큐엘 가드 부분입니다.

    import { ExecutionContext } from '@nestjs/common';
    import { GqlExecutionContext } from '@nestjs/graphql';
    import { AuthGuard } from '@nestjs/passport';
    
    // graphql 인가 가드 설정
    export const GqlAuthGuard = (name: string) => {
      return class GqlAuthGuard extends AuthGuard(name) {
        getRequest(context: ExecutionContext) {
          const gqlContext = GqlExecutionContext.create(context);
    
          return gqlContext.getContext().req;
        }
      };
    };
    

  • jwt google 부분입니다.

import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-google-oauth20';

export class JwtGoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor() {
    super({
      clientID: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
   
      callbackURL: 'http://localhost:3001/login',
      scope: ['email', 'profile'],
    });
  }

  validate(accessToken, profile) {
    console.log('profile:', profile);

    return {
     ...
    };
  }
}


혹시 제가 실수한 부분이있을까요?

답변 3

0

노원두님의 프로필 이미지
노원두
지식공유자

2024. 10. 08. 19:46

안녕하세요! 반가우면반갑다고해님!

맨 위의 에러 내용을 보니, res.setHeader is not a function 이라고 되어 있네요!

  1. res 부분에 context.res가 제대로 전달되고 있는지 확인이 필요할 것 같아요!

  2. 만약, 제대로 전달되고 있는 것 같다면, 추가적으로 app.module에서 GraphqlModule의 context 설정에서 req, res가 제대로 전달되고 있는지 확인해 주세요!

     

    GraphQLModule.forRoot<ApolloDriverConfig>({
        context: ({ req, res }) => ({ req, res }), // req는 기본적으로 들어오지만, res는 이걸 작성해야만 들어옴
    }),

     

0

rina carlos님의 프로필 이미지

2024. 08. 15. 08:51

SITUS SLOT GACOR TERBAIK DAN TERPERCAYA

new 1.jpg

 

FURI88 : DAFTAR LINK SLOT GACOR TERBAIK
HARI INI

Menyediakan beragam jenis permainan GAME SLOT Terlengkap dan tergacor

Pragmatic Play | PG soft | spadeGaming | JOKER | Habanero | NoLimit | PlayStar,

NextSpin | AdvantPlay | Microgaming | FLOW Gaming | CQ9 Gaming | Red Tiger -

dan masih banyak Provider Game Slot tergacor lainnya.

https://www.billetcool.com/

https://freehostnews.com/

https://99naga.com/

https://fondafrontera.com/

https://loftiespacesandevents.com/

https://www.politeknik-med/

https://reciperaaga.com/

https://www.ivermectinoral.com/

https://slotgacor-7oa.pages.dev/

https://slot-gacor-dse.pages.dev/

https://pauldsmart.com/

https://benejim.info/

https://furi88win.tumblr.com/
#FURI88 #FURI88 SLOT GACOR #FURI88 SITUS SLOT

-2

Furi88online님의 프로필 이미지

2024. 07. 17. 03:07