{"id":21074999,"url":"https://github.com/marchellodev/authjs-adapter-sql","last_synced_at":"2026-04-26T17:31:39.640Z","repository":{"id":174254447,"uuid":"651985709","full_name":"marchellodev/authjs-adapter-sql","owner":"marchellodev","description":"Mysql/Postgres adapter for Auth.js","archived":false,"fork":false,"pushed_at":"2023-06-10T18:17:01.000Z","size":445,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-31T04:58:59.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"roelandmoors/authjs-adapter-sql","license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marchellodev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-10T17:54:33.000Z","updated_at":"2023-06-10T17:55:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"27c16750-bb33-4106-932b-d3317cacff4c","html_url":"https://github.com/marchellodev/authjs-adapter-sql","commit_stats":null,"previous_names":["marchellodev/authjs-adapter-sql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marchellodev/authjs-adapter-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marchellodev%2Fauthjs-adapter-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marchellodev%2Fauthjs-adapter-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marchellodev%2Fauthjs-adapter-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marchellodev%2Fauthjs-adapter-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marchellodev","download_url":"https://codeload.github.com/marchellodev/authjs-adapter-sql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marchellodev%2Fauthjs-adapter-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32307010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T17:23:19.671Z","status":"ssl_error","status_checked_at":"2026-04-26T17:23:19.195Z","response_time":129,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T19:19:08.429Z","updated_at":"2026-04-26T17:31:39.624Z","avatar_url":"https://github.com/marchellodev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://authjs.dev\" target=\"_blank\"\u003e\n    \u003cimg height=\"64px\" src=\"https://authjs.dev/img/logo/logo-sm.png\" /\u003e\n  \u003c/a\u003e\n  \u003ch3 align=\"center\"\u003e\u003cb\u003eSql Adapter\u003c/b\u003e - NextAuth.js / Auth.js\u003c/a\u003e\u003c/h3\u003e\n\u003c/p\u003e\n\n[![mysql](https://github.com/roelandmoors/authjs-adapter-sql/actions/workflows/mysql_test.yml/badge.svg)](https://github.com/roelandmoors/authjs-adapter-sql/actions/workflows/mysql_test.yml)\n[![postgres](https://github.com/roelandmoors/authjs-adapter-sql/actions/workflows/postgres_test.yml/badge.svg)](https://github.com/roelandmoors/authjs-adapter-sql/actions/workflows/postgres_test.yml)\n\n---\n\nThis adapter uses plain sql statements to integrate with [Authjs](https://authjs.dev/).\n\nSupport for Mysql ([mysql2](https://github.com/sidorares/node-mysql2)) and Postgres ([pg-promise](https://github.com/vitaly-t/pg-promise)).  \nAlso works with the [PlanetScale Serverless Driver](https://github.com/planetscale/database-js), [Neon Serverless Driver](https://github.com/neondatabase/serverless), [Kysely](https://kysely-org.github.io/kysely/), [Knex](https://knexjs.org/) and [Slonik](https://github.com/gajus/slonik).\n\nYou can create a custom helper function to support other drivers if needed.\n\n## Configuration\n\nYou can set an optional table prefix/postgres schema.\n\n```ts\nconst config = {\n  prefix: \"auth_\", //or for example 'auth.' for a postgres schema\n};\n\nexport default NextAuth({\n  adapter: SqlAdapter(helpers, config),\n  providers: [],\n});\n```\n\n## Default vs named imports\n\nIf you have problems with default imports in modules, than you can also try named imports.\n\nInstead of this:\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport buildMysql2Helpers from \"authjs-adapter-sql/mysql2\";\n```\n\ntry this:\n\n```ts\nimport { SqlAdapter } from \"authjs-adapter-sql\";\nimport { buildMysql2Helpers } from \"authjs-adapter-sql/mysql2\";\n```\n\n## How to use with Mysql2\n\nInstall:\n\n```\nnpm i authjs-adapter-sql mysql2\n```\n\nuse [mysql.sql](mysql.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport * as mysql from \"mysql2/promise\";\nimport buildMysql2Helpers from \"authjs-adapter-sql/mysql2\";\n\nfunction getConnection() {\n  return mysql.createConnection({\n    host: \"127.0.0.1\",\n    user: \"root\",\n    database: \"fancydb\",\n  });\n}\n\n// you can create your own helpers for custom logic\nconst mysql2Helpers = buildMysql2Helpers(getConnection);\n\nexport default NextAuth({\n  adapter: SqlAdapter(mysql2Helpers),\n  providers: [],\n});\n```\n\nWhen using the new app dir in NextJs you may need this:\n\n```ts\nconst nextConfig = {\n  experimental: {\n    appDir: true,\n    serverComponentsExternalPackages: [\"mysql2\"],\n  },\n};\n```\n\n## How to use with PlanetScale serverless driver\n\nInstall:\n\n```\nnpm i authjs-adapter-sql @planetscale/database\n```\n\nuse [mysql.sql](mysql.sql) to create the tables.\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport buildPlanetScaleHelpers from \"authjs-adapter-sql/planetscale\";\n\nconst client = new Client(config);\n\n// you can create your own helpers for custom logic\nconst psHelpers = buildPlanetScaleHelpers(client);\n\nexport default NextAuth({\n  adapter: SqlAdapter(psHelpers),\n  providers: [],\n});\n```\n\n- https://planetscale.com/docs/learn/operating-without-foreign-key-constraints\n- https://planetscale.com/docs/tutorials/planetscale-serverless-driver\n\n## How to use with pg-promise\n\nInstall:\n\n```\nnpm i authjs-adapter-sql pg-promise\n```\n\nuse [postgres.sql](postgres.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport pgPromise from \"pg-promise\";\nimport buildPgPromiseHelpers from \"../src/pg-promise\";\n\nconst pgp = pgPromise();\nconst db = pgp(\"postgres://postgres:postgres@localhost:5432/postgres\");\n\nfunction getConnection() {\n  return db;\n}\n\n// you can create your own helpers for custom logic\nconst pgHelpers = buildPgPromiseHelpers(getConnection);\n\nexport default NextAuth({\n  adapter: SqlAdapter(pgHelpers),\n  providers: [],\n});\n```\n\n## How to use with Neon Serverless Driver\n\nInstall:\n\n```\nnpm i authjs-adapter-sql @neondatabase/serverless\n```\n\nuse [postgres.sql](postgres.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport buildNeonHelpers from \"authjs-adapter-sql/neon\";\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL });\n\n// you can create your own helpers for custom logic\nconst helpers = buildNeonHelpers(pool);\n\nexport default NextAuth({\n  adapter: SqlAdapter(helpers),\n  providers: [],\n});\n```\n\n## How to use with Kysely\n\nInstall:\n\n```\nnpm i kysely mysql2 (or pg)\n```\n\nuse [mysql.sql](mysql.sql) or [postgres.sql](postgres.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport { Kysely, MysqlDialect } from \"kysely\";\nimport buildKyselyHelpers from \"authjs-adapter-sql/kysely\";\n\nconst pool = mysql.createPool({\n  host: process.env.DB_HOST,\n  user: process.env.DB_USER,\n  password: process.env.DB_PASSWORD,\n  database: process.env.DB_DATABASE,\n});\n\nconst db = new Kysely({\n  dialect: new MysqlDialect({\n    pool,\n  }),\n});\n\n// you can create your own helpers for custom logic\nconst helpers = buildKyselyHelpers(db, \"mysql\"); //or postgres\n\nexport default NextAuth({\n  adapter: SqlAdapter(helpers),\n  providers: [],\n});\n```\n\n## How to use with Knex\n\nInstall:\n\n```\nnpm i knex mysql2 (or pg)\n```\n\nuse [mysql.sql](mysql.sql) or [postgres.sql](postgres.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport { Knex, knex } from \"knex\";\nimport buildKnexHelpers from \"authjs-adapter-sql/knex\";\n\nconst config: Knex.Config = {\n  client: \"mysql2\",\n  connection: {\n    host: process.env.DB_HOST,\n    user: process.env.DB_USER,\n    password: process.env.DB_PASSWORD,\n    database: process.env.DB_DATABASE,\n  },\n};\n\nconst knexInstance = knex(config);\n\n// you can create your own helpers for custom logic\nconst helpers = buildKnexHelpers(knexInstance, \"mysql\"); //or postgres\n\nexport default NextAuth({\n  adapter: SqlAdapter(helpers),\n  providers: [],\n});\n```\n\n## How to use with Slonik\n\nInstall:\n\n```\nnpm i slonik pg\n```\n\nuse [postgres.sql](postgres.sql) to create the tables.\n(you can add foreign keys if needed)\n\n```ts\nimport SqlAdapter from \"authjs-adapter-sql\";\nimport buildSlonikHelpers from \"authjs-adapter-sql/slonik\";\nimport { createPool } from \"slonik\";\n\nconst poolPromise = createPool(\"postgres://postgres:postgres@localhost:5432/postgres\");\n\nfunction getConnection() {\n  return poolPromise;\n}\n\n// you can create your own helpers for custom logic\nconst helpers = buildSlonikHelpers(getConnection);\n\nexport default NextAuth({\n  adapter: SqlAdapter(helpers),\n  providers: [],\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarchellodev%2Fauthjs-adapter-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarchellodev%2Fauthjs-adapter-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarchellodev%2Fauthjs-adapter-sql/lists"}