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

진슈님의 프로필 이미지

작성한 질문수

탄탄한 백엔드 NestJS, 기초부터 심화까지

PostgreSQL 셋업 (with docker) & TypeORM과 연결

실행오류

작성

·

1.4K

1

db연결은 잘되는데

쿼리 날리면 아래 에러가 뜨네요.

express-session 설치해봤는데 동일 메세지가 나옵니다.

 

ERROR [ExceptionsHandler] Login sessions require session support. Did you forget to use `express-session` middleware?

Error: Login sessions require session support. Did you forget to use `express-session` middleware?

    at SessionStrategy.authenticate (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/passport/lib/strategies/session.js:46:41)

    at attempt (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/passport/lib/middleware/authenticate.js:369:16)

    at authenticate (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/passport/lib/middleware/authenticate.js:370:7)

    at Layer.handle [as handle_request] (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/layer.js:95:5)

    at trim_prefix (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/index.js:317:13)

    at /Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/index.js:284:7

    at Function.process_params (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/index.js:335:12)

    at next (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/index.js:275:10)

    at initialize (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/passport/lib/middleware/initialize.js:89:5)

    at Layer.handle [as handle_request] (/Users/jinsyu/dev/teaching-typeorm-in-the-nest-main/node_modules/express/lib/router/layer.js:95:5)

 

 

 

답변 3

0

2023-02-12 :
passport 미들웨어 사용보다 위에 적어주셔야 동작하였습니다.

private async setUpGlobalMiddleware() {
    this.server.enableCors({
      origin: this.corsOriginList,
      credentials: true,
    })
    this.server.use(cookieParser())
    this.setUpBasicAuth()
    this.setUpOpenAPIMidleware()
    this.server.useGlobalPipes(
      new ValidationPipe({
        transform: true,
      }),
    )

// 이 부분 적용
    this.server.use(
      expressSession({
        secret: 'SECRET',
        resave: true,
        saveUninitialized: true,
      }),
    )
// -----------------
    this.server.use(passport.initialize())
    this.server.use(passport.session())
    this.server.useGlobalInterceptors(
      new ClassSerializerInterceptor(this.server.get(Reflector)),
    )
    this.server.useGlobalFilters(new HttpApiExceptionFilter())
  }

 

0

main.ts 의 setUpGlobalMiddleware() 함수 내에  아래코드를 추가합니다.
 
this.server.use(
  expressSession({
     secret: 'SECRET',
     resave: true,
     saveUninitialized: true,
  }),
)

0

윤상석님의 프로필 이미지
윤상석
지식공유자

안녕하세요!

해당 에러가 발생하는 경우

main.ts에서 express-session 미들웨어를 등록해주세요!

 

 

import * as expressSession from "express-session";

...

app.use(expressSession);

...

 

진슈님의 프로필 이미지

작성한 질문수

질문하기