next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

feat(adapter): add Postgres.js adapter

Open mustaqimarifin opened this issue 1 year ago โ€ข 3 comments

โ˜•๏ธ 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

mustaqimarifin avatar Jan 23 '24 20:01 mustaqimarifin

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

vercel[bot] avatar Jan 23 '24 20:01 vercel[bot]

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);

hillac avatar Jan 24 '24 08:01 hillac

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..

mustaqimarifin avatar Jan 25 '24 11:01 mustaqimarifin

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

ThangHuuVu avatar Jun 08 '24 08:06 ThangHuuVu