From 41b0b8f191a39783845a18e95b8707ae658906ef Mon Sep 17 00:00:00 2001 From: Amadeusz Winogrodzki Date: Thu, 25 Jul 2024 17:06:19 +0200 Subject: [PATCH] feat: added `path` option to `redirectToHome` helper function --- CHANGELOG.md | 7 ------- jest.config.js | 6 +++--- src/next/middleware.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3613a0e8..2991764a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,3 @@ -# [1.7.0-canary.1](https://github.com/awinogrodzki/next-firebase-auth-edge/compare/v1.6.2...v1.7.0-canary.1) (2024-07-25) - - -### Features - -* introduced `refreshCookiesWithIdToken` function to enable login using Server Actions ([#212](https://github.com/awinogrodzki/next-firebase-auth-edge/issues/212)) ([6cd0b13](https://github.com/awinogrodzki/next-firebase-auth-edge/commit/6cd0b138036ff0f4fcfa91d786fca5255cfa2654)) - # [1.7.0-canary.1](https://github.com/awinogrodzki/next-firebase-auth-edge/compare/v1.6.1...v1.7.0-canary.1) (2024-07-16) diff --git a/jest.config.js b/jest.config.js index cebf64b0..6d5fdb9b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,7 @@ module.exports = { + setupFiles: ['dotenv/config'], + testEnvironment: 'node', + setupFilesAfterEnv: ['/jest.setup.ts'], transform: { '^.+\\.tsx?$': [ 'ts-jest', @@ -8,7 +11,4 @@ module.exports = { ], '^.+\\.jsx?$': 'babel-jest', }, - setupFiles: ['dotenv/config'], - testEnvironment: 'node', - setupFilesAfterEnv: ['/jest.setup.ts'], }; diff --git a/src/next/middleware.ts b/src/next/middleware.ts index 8b4205a2..eefde9af 100644 --- a/src/next/middleware.ts +++ b/src/next/middleware.ts @@ -34,9 +34,18 @@ export interface CreateAuthMiddlewareOptions { enableMultipleCookies?: boolean; } -export function redirectToHome(request: NextRequest) { +interface RedirectToHomeOptions { + path: string; +} + +export function redirectToHome( + request: NextRequest, + options: RedirectToHomeOptions = { + path: '/' + } +) { const url = request.nextUrl.clone(); - url.pathname = '/'; + url.pathname = options.path; url.search = ''; return NextResponse.redirect(url); }