diff --git a/.changeset/strange-mugs-know.md b/.changeset/strange-mugs-know.md new file mode 100644 index 00000000..5b4d101f --- /dev/null +++ b/.changeset/strange-mugs-know.md @@ -0,0 +1,5 @@ +--- +'@supabase/auth-helpers-nextjs': patch +--- + +Upgrade Next.js and remove custom type for WritableRequestCookies diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index c474b936..3421d7cb 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -31,7 +31,7 @@ "@types/set-cookie-parser": "^2.4.2", "@supabase/supabase-js": "2.19.0", "config": "workspace:*", - "next": "^13.4.2", + "next": "^13.4.3", "react": "^18.2.0", "react-dom": "^18.2.0", "rimraf": "^4.1.1", diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index 1de0a6f6..de052b65 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -1,14 +1,6 @@ -import type { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies'; -import type { CookieOptions } from '@supabase/auth-helpers-shared'; - // Types export type { Session, User, SupabaseClient } from '@supabase/supabase-js'; -// TODO! Remove this one 👇 when Next.js update their types for Route Handlers and Server Actions -export type WritableRequestCookies = ReadonlyRequestCookies & { - set: (name: string, value: string, options?: CookieOptions) => void; -}; - export { createPagesBrowserClient } from './pagesBrowserClient'; export { createPagesServerClient } from './pagesServerClient'; export { createMiddlewareClient } from './middlewareClient'; diff --git a/packages/nextjs/src/routeHandlerClient.ts b/packages/nextjs/src/routeHandlerClient.ts index 9a37ed9a..813d09c7 100644 --- a/packages/nextjs/src/routeHandlerClient.ts +++ b/packages/nextjs/src/routeHandlerClient.ts @@ -6,13 +6,12 @@ import { createSupabaseClient } from '@supabase/auth-helpers-shared'; -import type { WritableRequestCookies } from './index'; -import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies'; +import type { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies'; class NextRouteHandlerAuthStorageAdapter extends CookieAuthStorageAdapter { constructor( private readonly context: { - cookies: () => WritableRequestCookies; + cookies: () => ReadonlyRequestCookies; }, cookieOptions?: CookieOptions ) { @@ -29,6 +28,7 @@ class NextRouteHandlerAuthStorageAdapter extends CookieAuthStorageAdapter { } protected deleteCookie(name: string): void { const nextCookies = this.context.cookies(); + // @ts-expect-error Next.js need to fix their type for cookie options (3rd parameter on .set method) nextCookies.set(name, '', { maxAge: 0 }); @@ -42,8 +42,7 @@ export function createRouteHandlerClient< : string & keyof Database >( context: { - // TODO! Remove `ReadonlyRequestCookies` when Next.js fixes ts defs for Route Handlers and Server Actions - cookies: () => ReadonlyRequestCookies | WritableRequestCookies; + cookies: () => ReadonlyRequestCookies; }, { supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL, @@ -63,12 +62,6 @@ export function createRouteHandlerClient< ); } - // TODO! Remove this type narrowing statement 👇 when Next.js fixes ts defs for Route Handlers and Server Actions - const narrowedContext = { - ...context, - cookies: context.cookies as () => WritableRequestCookies - }; - return createSupabaseClient(supabaseUrl, supabaseKey, { ...options, global: { @@ -80,7 +73,7 @@ export function createRouteHandlerClient< }, auth: { storageKey: cookieOptions?.name, - storage: new NextRouteHandlerAuthStorageAdapter(narrowedContext, cookieOptions) + storage: new NextRouteHandlerAuthStorageAdapter(context, cookieOptions) } }); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8754ad0c..fc990397 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -286,8 +286,8 @@ importers: specifier: workspace:* version: link:../config next: - specifier: ^13.4.2 - version: 13.4.2(react-dom@18.2.0)(react@18.2.0) + specifier: ^13.4.3 + version: 13.4.3(react-dom@18.2.0)(react@18.2.0) react: specifier: ^18.2.0 version: 18.2.0 @@ -2369,8 +2369,8 @@ packages: resolution: {integrity: sha512-Qb6WPuRriGIQ19qd6NBxpcrFOfj8ziN7l9eZUfwff5gl4zLXluqtuZPddYZM/oWjN53ZYcuRXzL+oowKyJeYtA==} dev: false - /@next/env@13.4.2: - resolution: {integrity: sha512-Wqvo7lDeS0KGwtwg9TT9wKQ8raelmUxt+TQKWvG/xKfcmDXNOtCuaszcfCF8JzlBG1q0VhpI6CKaRMbVPMDWgw==} + /@next/env@13.4.3: + resolution: {integrity: sha512-pa1ErjyFensznttAk3EIv77vFbfSYT6cLzVRK5jx4uiRuCQo+m2wCFAREaHKIy63dlgvOyMlzh6R8Inu8H3KrQ==} dev: true /@next/eslint-plugin-next@12.3.1: @@ -2463,8 +2463,8 @@ packages: dev: false optional: true - /@next/swc-darwin-arm64@13.4.2: - resolution: {integrity: sha512-6BBlqGu3ewgJflv9iLCwO1v1hqlecaIH2AotpKfVUEzUxuuDNJQZ2a4KLb4MBl8T9/vca1YuWhSqtbF6ZuUJJw==} + /@next/swc-darwin-arm64@13.4.3: + resolution: {integrity: sha512-yx18udH/ZmR4Bw4M6lIIPE3JxsAZwo04iaucEfA2GMt1unXr2iodHUX/LAKNyi6xoLP2ghi0E+Xi1f4Qb8f1LQ==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -2498,8 +2498,8 @@ packages: dev: false optional: true - /@next/swc-darwin-x64@13.4.2: - resolution: {integrity: sha512-iZuYr7ZvGLPjPmfhhMl0ISm+z8EiyLBC1bLyFwGBxkWmPXqdJ60mzuTaDSr5WezDwv0fz32HB7JHmRC6JVHSZg==} + /@next/swc-darwin-x64@13.4.3: + resolution: {integrity: sha512-Mi8xJWh2IOjryAM1mx18vwmal9eokJ2njY4nDh04scy37F0LEGJ/diL6JL6kTXi0UfUCGbMsOItf7vpReNiD2A==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -2585,8 +2585,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-gnu@13.4.2: - resolution: {integrity: sha512-2xVabFtIge6BJTcJrW8YuUnYTuQjh4jEuRuS2mscyNVOj6zUZkom3CQg+egKOoS+zh2rrro66ffSKIS+ztFJTg==} + /@next/swc-linux-arm64-gnu@13.4.3: + resolution: {integrity: sha512-aBvtry4bxJ1xwKZ/LVPeBGBwWVwxa4bTnNkRRw6YffJnn/f4Tv4EGDPaVeYHZGQVA56wsGbtA6nZMuWs/EIk4Q==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -2620,8 +2620,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-musl@13.4.2: - resolution: {integrity: sha512-wKRCQ27xCUJx5d6IivfjYGq8oVngqIhlhSAJntgXLt7Uo9sRT/3EppMHqUZRfyuNBTbykEre1s5166z+pvRB5A==} + /@next/swc-linux-arm64-musl@13.4.3: + resolution: {integrity: sha512-krT+2G3kEsEUvZoYte3/2IscscDraYPc2B+fDJFipPktJmrv088Pei/RjrhWm5TMIy5URYjZUoDZdh5k940Dyw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -2655,8 +2655,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-gnu@13.4.2: - resolution: {integrity: sha512-NpCa+UVhhuNeaFVUP1Bftm0uqtvLWq2JTm7+Ta48+2Uqj2mNXrDIvyn1DY/ZEfmW/1yvGBRaUAv9zkMkMRixQA==} + /@next/swc-linux-x64-gnu@13.4.3: + resolution: {integrity: sha512-AMdFX6EKJjC0G/CM6hJvkY8wUjCcbdj3Qg7uAQJ7PVejRWaVt0sDTMavbRfgMchx8h8KsAudUCtdFkG9hlEClw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -2690,8 +2690,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-musl@13.4.2: - resolution: {integrity: sha512-ZWVC72x0lW4aj44e3khvBrj2oSYj1bD0jESmyah3zG/3DplEy/FOtYkMzbMjHTdDSheso7zH8GIlW6CDQnKhmQ==} + /@next/swc-linux-x64-musl@13.4.3: + resolution: {integrity: sha512-jySgSXE48shaLtcQbiFO9ajE9mqz7pcAVLnVLvRIlUHyQYR/WyZdK8ehLs65Mz6j9cLrJM+YdmdJPyV4WDaz2g==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -2725,8 +2725,8 @@ packages: dev: false optional: true - /@next/swc-win32-arm64-msvc@13.4.2: - resolution: {integrity: sha512-pLT+OWYpzJig5K4VKhLttlIfBcVZfr2+Xbjra0Tjs83NQSkFS+y7xx+YhCwvpEmXYLIvaggj2ONPyjbiigOvHQ==} + /@next/swc-win32-arm64-msvc@13.4.3: + resolution: {integrity: sha512-5DxHo8uYcaADiE9pHrg8o28VMt/1kR8voDehmfs9AqS0qSClxAAl+CchjdboUvbCjdNWL1MISCvEfKY2InJ3JA==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -2760,8 +2760,8 @@ packages: dev: false optional: true - /@next/swc-win32-ia32-msvc@13.4.2: - resolution: {integrity: sha512-dhpiksQCyGca4WY0fJyzK3FxMDFoqMb0Cn+uDB+9GYjpU2K5//UGPQlCwiK4JHxuhg8oLMag5Nf3/IPSJNG8jw==} + /@next/swc-win32-ia32-msvc@13.4.3: + resolution: {integrity: sha512-LaqkF3d+GXRA5X6zrUjQUrXm2MN/3E2arXBtn5C7avBCNYfm9G3Xc646AmmmpN3DJZVaMYliMyCIQCMDEzk80w==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] @@ -2795,8 +2795,8 @@ packages: dev: false optional: true - /@next/swc-win32-x64-msvc@13.4.2: - resolution: {integrity: sha512-O7bort1Vld00cu8g0jHZq3cbSTUNMohOEvYqsqE10+yfohhdPHzvzO+ziJRz4Dyyr/fYKREwS7gR4JC0soSOMw==} + /@next/swc-win32-x64-msvc@13.4.3: + resolution: {integrity: sha512-jglUk/x7ZWeOJWlVoKyIAkHLTI+qEkOriOOV+3hr1GyiywzcqfI7TpFSiwC7kk1scOiH7NTFKp8mA3XPNO9bDw==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -8613,8 +8613,8 @@ packages: - babel-plugin-macros dev: false - /next@13.4.2(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-aNFqLs3a3nTGvLWlO9SUhCuMUHVPSFQC0+tDNGAsDXqx+WJDFSbvc233gOJ5H19SBc7nw36A9LwQepOJ2u/8Kg==} + /next@13.4.3(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-FV3pBrAAnAIfOclTvncw9dDohyeuEEXPe5KNcva91anT/rdycWbgtu3IjUj4n5yHnWK8YEPo0vrUecHmnmUNbA==} engines: {node: '>=16.8.0'} hasBin: true peerDependencies: @@ -8634,7 +8634,7 @@ packages: sass: optional: true dependencies: - '@next/env': 13.4.2 + '@next/env': 13.4.3 '@swc/helpers': 0.5.1 busboy: 1.6.0 caniuse-lite: 1.0.30001425 @@ -8644,15 +8644,15 @@ packages: styled-jsx: 5.1.1(react@18.2.0) zod: 3.21.4 optionalDependencies: - '@next/swc-darwin-arm64': 13.4.2 - '@next/swc-darwin-x64': 13.4.2 - '@next/swc-linux-arm64-gnu': 13.4.2 - '@next/swc-linux-arm64-musl': 13.4.2 - '@next/swc-linux-x64-gnu': 13.4.2 - '@next/swc-linux-x64-musl': 13.4.2 - '@next/swc-win32-arm64-msvc': 13.4.2 - '@next/swc-win32-ia32-msvc': 13.4.2 - '@next/swc-win32-x64-msvc': 13.4.2 + '@next/swc-darwin-arm64': 13.4.3 + '@next/swc-darwin-x64': 13.4.3 + '@next/swc-linux-arm64-gnu': 13.4.3 + '@next/swc-linux-arm64-musl': 13.4.3 + '@next/swc-linux-x64-gnu': 13.4.3 + '@next/swc-linux-x64-musl': 13.4.3 + '@next/swc-win32-arm64-msvc': 13.4.3 + '@next/swc-win32-ia32-msvc': 13.4.3 + '@next/swc-win32-x64-msvc': 13.4.3 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros