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

[Bug]: Mismatched types between cookies from next/headers and required cookies from handleRequest() #630

Closed
ernestoresende opened this issue May 19, 2023 · 2 comments
Labels
bug Something ain't right...

Comments

@ernestoresende
Copy link
Contributor

Package

lucia-auth

Describe the bug

Using handleRequest() from within a Router Handler (app directory), on Next.js ^13.4.3 with the nextjs middleware will lead to a typing mismatch between cookies from next/headers and the required cookies argument from handleRequest().

Type '() => ReadonlyRequestCookies' is not assignable to type '() => { set?: ((name: string, value: string, options?: CookieAttributes | undefined) => void) | undefined; get: (name: string) => { name: string; value: string; } | undefined; }'.
  Call signature return types 'ReadonlyRequestCookies' and '{ set?: ((name: string, value: string, options?: CookieAttributes | undefined) => void) | undefined; get: (name: string) => { name: string; value: string; } | undefined; }' are incompatible.
    The types of 'set' are incompatible between these types.
      Type '(...args: [key: string, value: string] | [options: RequestCookie]) => RequestCookies' is not assignable to type '(name: string, value: string, options?: CookieAttributes | undefined) => void'.
        Types of parameters 'args' and 'name' are incompatible.
          Type '[name: string, value: string, options?: CookieAttributes | undefined]' is not assignable to type '[key: string, value: string] | [options: RequestCookie]'.
            Type '[name: string, value: string, options?: CookieAttributes | undefined]' is not assignable to type '[key: string, value: string]'.
              Target allows only 2 element(s) but source may have more.

Even with the mismatched typings, correct behavior of handleRequest() within the Route Handler is still maintained (it still correctly sets the session cookie on the client).

Downgrading back to Next.js 13.4.2 removes the type error.

Seems to be related to: vercel/next.js#49806

@ernestoresende ernestoresende added the bug Something ain't right... label May 19, 2023
@ernestoresende ernestoresende changed the title [Bug]: Mismatched types between cookies from next/headers and required cookies from handleRequest [Bug]: Mismatched types between cookies from next/headers and required cookies from handleRequest() May 19, 2023
@pilcrowonpaper
Copy link
Member

I'm like 99% sure Next.js has the wrong types.

Docs + actual behavior:

cookies().set('name', 'lee');
cookies().set('name', 'lee', { secure: true });
cookies().set({
    name: 'name',
    value: 'lee',
    httpOnly: true,
    path: '/',
});

Types:

cookies().set('name', 'lee');
cookies().set({
    name: 'name',
    value: 'lee',
});

Ref: https://github.com/vercel/next.js/blob/ddb5b1b2f56bbf856dc0901be1cbac54cfde3959/packages/next/src/compiled/%40edge-runtime/cookies/index.d.ts#L149

@pilcrowonpaper
Copy link
Member

pilcrowonpaper commented May 20, 2023

Looks like it got fixed with vercel/next.js#50052

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something ain't right...
Projects
None yet
Development

No branches or pull requests

2 participants