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

Type issue in 4.24.8 Adapter #11916

Open
tacomanator opened this issue Sep 26, 2024 · 10 comments
Open

Type issue in 4.24.8 Adapter #11916

tacomanator opened this issue Sep 26, 2024 · 10 comments
Labels
bug Something isn't working TypeScript Issues relating to TypeScript

Comments

@tacomanator
Copy link

Environment

  System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 259.67 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.11.0 - ~/Library/pnpm/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  Browsers:
    Chrome: 129.0.6668.70
    Safari: 17.6
  npmPackages:
    next: 14.2.13 => 14.2.13 
    next-auth: ^4.24.8 => 4.24.8 
    react: ^18 => 18.3.1 

Reproduction URL

https://github.com/tacomanator/next-auth-adapter-4.24.8

Describe the issue

In upgrading from 4.24.7 to 4.24.8, the parameter types for the following Adapter methods are missing (i.e. becoming implicit any):

  • createUser
  • linkAccount
  • unlinkAccount

How to reproduce

try to build typescript project with custom Adapter. For example, the reproduction repository uses the following:

import { Adapter, AdapterSession, AdapterUser } from "next-auth/adapters";

const data: { user: AdapterUser; session: AdapterSession } = {
  user: { id: "test", name: "test", email: "test", emailVerified: new Date() },
  session: { sessionToken: "test", userId: "test", expires: new Date() },
};

export default function MyAdapter(): Adapter {
  return {
    async createUser(user) {
      console.log(user);
      return;
    },
    async getUser(id) {
      console.log(id);
      return null;
    },
    async getUserByEmail(email) {
      console.log(email);
      return null;
    },
    async getUserByAccount({ providerAccountId, provider }) {
      console.log(providerAccountId, provider);
      return null;
    },
    async updateUser(user) {
      console.log(user);
      return data.user;
    },
    async deleteUser(userId) {
      console.log(userId);
      return;
    },
    async linkAccount(account) {
      console.log(account);
      return null;
    },
    async unlinkAccount({ providerAccountId, provider }) {
      console.log(providerAccountId, provider);
      return null;
    },
    async createSession({ sessionToken, userId, expires }) {
      console.log(sessionToken, userId, expires);
      return data.session;
    },
    async getSessionAndUser(sessionToken) {
      console.log(sessionToken);
      return null;
    },
    async updateSession({ sessionToken }) {
      console.log(sessionToken);
      return null;
    },
    async deleteSession(sessionToken) {
      console.log(sessionToken);
      return null;
    },
    async createVerificationToken({ identifier, expires, token }) {
      console.log(identifier, expires, token);
      return null;
    },
    async useVerificationToken({ identifier, token }) {
      console.log(identifier, token);
      return null;
    },
  };
}

Expected behavior

Types are present for parameters and can build.

@tacomanator tacomanator added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 26, 2024
@balazsorban44 balazsorban44 added TypeScript Issues relating to TypeScript and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 26, 2024
@balazsorban44
Copy link
Member

balazsorban44 commented Sep 26, 2024

Looks related to #11562

Based on #9493 (comment) and my own local testing, I thought it fixed the issue...

But it introduced a new one in case of custom adapters. 🙁

I will try to look into this.

@kiruushaaa
Copy link

Looks related to #11562

Based on #9493 (comment) and my own local testing, I thought it fixed the issue...

But it introduced a new one in case of custom adapters. 🙁

I will try to look into this.

Hi. The issue seems to be present (and/or breaking CI/CD) when one do not install @auth/core or smth like that (e.g. upgrading to the 5th version[?]). So I assume you just imported types from that package and here we are.

Maybe this information will be helpful

image

@huksley
Copy link

huksley commented Oct 6, 2024

Yes I have a same issue. Using Prisma adapter.

@maxdeichmann

This comment has been minimized.

@balazsorban44
Copy link
Member

Anyone saying same issue, add a reproduction. Would help to see how this regressed.

@maxdeichmann
Copy link

maxdeichmann commented Oct 9, 2024

We have a branch to upgrade next-auth here: langfuse/langfuse#3602
If fails with:

./src/server/auth.ts:274:20
Type error: Parameter 'profile' implicitly has an 'any' type.

  272 | const extendedPrismaAdapter: Adapter = {
  273 |   ...prismaAdapter,
> 274 |   async createUser(profile) {
      |                    ^
  275 |     if (!prismaAdapter.createUser)
  276 |       throw new Error("createUser not implemented");
  277 |     if (
 ELIFECYCLE  Command failed with exit code 1.
Error:  command finished with error: command (/home/runner/work/langfuse/langfuse/web) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (1)
Error: web#build: command (/home/runner/work/langfuse/langfuse/web) /home/runner/setup-pnpm/node_modules/.bin/pnpm run build exited (1)

 Tasks:    4 successful, 5 total
Cached:    0 cached, 5 total
  Time:    2m58.602s 
Failed:    web#build

 ERROR  run failed: command  exited (1)
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.

Here are also docs explaining how to get up and running with the repo.

@ari-becker
Copy link

Anyone saying same issue, add a reproduction. Would help to see how this regressed.

@balazsorban44 looking at https://github.com/nextauthjs/next-auth/pull/11562/files , I'll explain what I think the regression is to you.

The PR introduces an optional dependency on @auth/core, to be able to pull in import type { Adapter as FutureAdapter } from "@auth/core/adapters". Where @auth/core is present, the FutureAdapter["createUser"] successfully resolves to a real type, but if @auth/core is not present, then it causes TypeScript to resolve to the any type, causing TypeScript to break for users who both implement custom Adapters and have the noImplicitAnycompiler option.

... I'm not 100% sure of that though, I tried to pull in @auth/core as a dependency and I'm still getting the error :(

@maxdeichmann
Copy link

balazsorban44 i do not have noImplicitAny set in my project. Any other reason why this might be failing?

@MonstraG
Copy link

MonstraG commented Nov 6, 2024

In order to unblock upgrade to next.js 15 I had to specify the type for unlinkAccount function arguments myself.

Before:

import type { Adapter } from "next-auth/adapters";

function MyAdapter(): Adapter {
	return {
		async unlinkAccount({
			providerAccountId,
			provider
		}) {
			
		}
	};
}

After:

import type { Adapter, AdapterAccount } from "next-auth/adapters";

function MyAdapter(): Adapter {
	return {
		async unlinkAccount({
			providerAccountId,
			provider
		}: Pick<AdapterAccount, "provider" | "providerAccountId">) {
			
		}
	};
}

@maxdeichmann
Copy link

@balazsorban44 is there any update on this? I would really like to upgrade next-auth but I am blocked by this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TypeScript Issues relating to TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants