Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session refresh middleware 추가 #3564

Open
wants to merge 10 commits into
base: v13
Choose a base branch
from
Open

session refresh middleware 추가 #3564

wants to merge 10 commits into from

Conversation

guswl98
Copy link
Contributor

@guswl98 guswl98 commented Feb 11, 2025

PR 설명

트리플에서는 각 페이지에서 어떠한 함수를 사용하느냐에 따라 세션 갱신을 진행하기도, 하지 않기도 합니다. 따라서 트리플 서비스를 계속 사용하고 있었다고 하더라도 어떤 페이지에 접속하느냐에 따라 세션 갱신이 제각각으로 진행됩니다. 이를 통일해 모든 페이지에서 세션 갱신 로직을 실행할 수 있도록 미들웨어에 세션 갱신 로직을 추가합니다.

v14의 middlware를 참고했고 단지 세션 갱신의 역할만 할 뿐 페이지 접속을 막는 것이 아니기 때문에 response의 status는 수정하지 않는 쪽으로 진행했습니다.

middleware

기본적으로 세션을 갱신하는 로직을 실행하는 미들웨어를 제공합니다.

middleware.ts 파일 예시

import {
  constructMiddleware,
  oldTripleIosCookiesMiddleware,
  CustomMiddleware,
} from '@titicaca/react-contexts'
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server'

function testMiddleware(customMiddleware: CustomMiddleware) {
  return function middleware(request: NextRequest, event: NextFetchEvent) {
    return customMiddleware(request, event, NextResponse.next())
  }
}

export default constructMiddleware([
  oldTripleIosCookiesMiddleware,
  testMiddleware,
])

직접 CustomMiddleware를 작성하여 미들웨어 구성이 가능합니다.

middleware.ts 파일에서 next/server로부터 타입을 import하기 때문에 next.config.jsconfig.resolve.fallback = { fs: false }를 추가해야 오류가 발생하지 않습니다.

@guswl98 guswl98 self-assigned this Feb 11, 2025
@guswl98
Copy link
Contributor Author

guswl98 commented Feb 11, 2025

release-canary

Copy link

v13.42.2-pr-3564.4 has been published!

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 25.64103% with 58 lines in your changes missing coverage. Please review.

Project coverage is 10.15%. Comparing base (8d002e8) to head (f90bc04).

Files with missing lines Patch % Lines
.../react-contexts/src/middlewares/refresh-session.ts 14.63% 35 Missing ⚠️
...-contexts/src/middlewares/old-triple-ios-cookie.ts 31.81% 15 Missing ⚠️
packages/react-contexts/src/middlewares/chain.ts 20.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              v13    #3564      +/-   ##
==========================================
+ Coverage   10.10%   10.15%   +0.05%     
==========================================
  Files         727      732       +5     
  Lines       28236    28419     +183     
  Branches     7721     7765      +44     
==========================================
+ Hits         2852     2886      +34     
- Misses      25364    25513     +149     
  Partials       20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guswl98
Copy link
Contributor Author

guswl98 commented Feb 12, 2025

release-canary

Copy link

v13.42.2-pr-3564.5 has been published!

@guswl98
Copy link
Contributor Author

guswl98 commented Feb 13, 2025

release-canary

Copy link

v13.42.2-pr-3564.6 has been published!

@guswl98
Copy link
Contributor Author

guswl98 commented Feb 14, 2025

release-canary

Copy link

v13.42.2-pr-3564.8 has been published!

@guswl98 guswl98 added this to the 13.43.0 milestone Feb 14, 2025
@guswl98
Copy link
Contributor Author

guswl98 commented Feb 14, 2025

release-canary

@guswl98 guswl98 requested review from Munilive and dongoc February 14, 2025 05:54
Copy link

v13.42.2-pr-3564.9 has been published!

@guswl98 guswl98 marked this pull request as ready for review February 14, 2025 07:40
@guswl98 guswl98 requested a review from a team as a code owner February 14, 2025 07:40
@guswl98 guswl98 requested review from zzolain and dia-triple and removed request for a team February 14, 2025 07:40
newCookies.set(name, cookie)
})

const finalCookie = [...newCookies.values()].join('; ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map의 key는 사용하지 않아도 괜찮나요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants