next-auth
next-auth copied to clipboard
feat(adapter): add Postgres.js adapter
โ๏ธ Reasoning
Postgres.js is The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare and a great alternative for close to direct use of NextAuth with Postgres.
๐งข Checklist
- [x] Documentation
- [x] Tests
- [x] Ready to be merged
๐ซ Affected issues
๐ Resources
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
auth-docs | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | Jan 28, 2024 0:51am |
1 Ignored Deployment
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
next-auth-docs | โฌ๏ธ Ignored (Inspect) | Visit Preview | Jan 28, 2024 0:51am |
Below is also an option.
import postgres from "postgres";
import PostgresAdapter from "@auth/pg-adapter";
const sql = postgres({});
function createPgWrapper(sqlClient: postgres.Sql<{}>) {
return {
async query(queryString: string, params: any[]) {
const processedParams = params.map((param) =>param === undefined ? null : param);
const result = await sqlClient.unsafe(queryString, processedParams);
return { rows: result, rowCount: result.length };
},
};
}
const client = createPgWrapper(sql);
const adapter = PostgresAdapter(client as any);
Below is also an option.
import postgres from "postgres"; import PostgresAdapter from "@auth/pg-adapter"; const sql = postgres({}); function createPgWrapper(sqlClient: postgres.Sql<{}>) { return { async query(queryString: string, params: any[]) { const processedParams = params.map((param) =>param === undefined ? null : param); const result = await sqlClient.unsafe(queryString, processedParams); return { rows: result, rowCount: result.length }; }, }; } const client = createPgWrapper(sql); const adapter = PostgresAdapter(client as any);
ooh? rewrap the @auth/pg-adapter? Didnt occur to me lol..
Please read authjs.dev/guides/adapters/creating-a-database-adapter#official-adapter-guidelines and do the necessary changes. ๐
correction: the link should be https://authjs.dev/guides/creating-a-database-adapter