-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Kysely Adapter' Database interface mismatch with provided schema in docs and kysely schema rules #10441
Comments
The error
|
Are you using some kind of code gen? Then this snippet might help.
Found in the docs here: https://authjs.dev/reference/adapter/kysely#kyselyauthdb-t |
same error:
I follow all the instructions in the guide, but still always gives error, even with CodeGen, try with different package manager, npm, pnpm and bun. |
I used custom adapter with custom schema, hope it helps |
I also encountered this problem and solved it by modifying the types from the documentation. import { PostgresDialect } from "kysely";
import { Pool } from "pg";
// This adapter exports a wrapper of the original `Kysely` class called `KyselyAuth`,
// that can be used to provide additional type-safety.
// While using it isn't required, it is recommended as it will verify
// that the database interface has all the fields that Auth.js expects.
import { KyselyAuth } from "@auth/kysely-adapter";
import type { GeneratedAlways } from "kysely";
import type { AdapterAccountType } from "@auth/core/adapters";
interface Database {
User: {
id: string;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
password: string | null;
};
Account: {
id: GeneratedAlways<string>;
userId: string;
type: AdapterAccountType;
provider: string;
providerAccountId: string;
refresh_token?: string;
access_token?: string;
expires_at?: number;
token_type?: Lowercase<string>;
scope?: string;
id_token?: string;
session_state: string | null;
};
Session: {
id: GeneratedAlways<string>;
userId: string;
sessionToken: string;
expires: Date;
};
VerificationToken: {
identifier: string;
token: string;
expires: Date;
};
}
... Anyway, I see 2 problems there. The first is the modification of the type for next-auth/packages/core/src/adapters.ts Line 178 in a7491dc
And edit the documentation for
|
I'm using kysely-codegen; it automatically exports your DB interface, so, if you're using it, i'd recommend instead re-implementing the custom adapter as suggested by AchalS-iglu in #10441 (comment) because
|
Adapter type
@auth/kysely-adapter
Environment
System:
OS: Linux 6.7 EndeavourOS
CPU: (8) x64 AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx
Memory: 1.15 GB / 6.72 GB
Container: Yes
Shell: 5.2.26 - /bin/bash
Binaries:
Node: 21.4.0 - ~/.nvm/versions/node/v21.4.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v21.4.0/bin/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v21.4.0/bin/npm
bun: 1.0.31 - ~/.bun/bin/bun
Browsers:
Chromium: 122.0.6261.128
npmPackages:
@auth/drizzle-adapter: ^0.7.0 => 0.7.0
@auth/kysely-adapter: ^0.6.1 => 0.6.1
next: ^14.1.3 => 14.1.4
next-auth: ^4.24.6 => 4.24.7
react: 18.2.0 => 18.2.0
Reproduction URL
https://github.com/traveltoindia-co-in/ta
Describe the issue
So, I used the schema provided in the docs but it is incompatible with the adapter's constructor
KyselyAuth
. Look atsrc/types/authTypes.ts
. These types are then put into the Database interface insrc/types/database.ts
. Then that interface is further passed into the Adapter's constructor in filesrc/server/database.ts
, however it is incompatible. The Adapter uses standard typescript typing rather than Kysely's format, meanwhile the docs have proper schema.The adapter's internal database type refers to the core types.
Suggested interface for said type -
I hope this is appropriate in terms of Kysely (I have actually never used kysely before). Also, Kysely tells to
| null
instead of optional ? or undefined. If I were to use Selectable instead of T (T being any of the table model above) then I believe it would match perfectly. However I am getting numerous errors on trying to assign Database schema to the adapter's constructor, there could be more, I do not know.I hope I am correct I could be entirely wrong and using the lib incorrectly.
How to reproduce
Look at intellisense I suppose or run ts check
Expected behavior
No TS errors.
The text was updated successfully, but these errors were encountered: