Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
authjs-knexjs-adapter
Advanced tools
An adapter for Auth.js/NextAuth.js to allow you to connect to any database service via Knex.js.
An adapter for Auth.js/NextAuth.js to allow you to connect to any database service via Knex.js.
Install the package as a dependency in your project.
npm install authjs-knexjs-adapter
Note: Make sure you also install knex
and the appropriate database library for
your environment (e.g. mysql2
).
Import the adapter into pages/api/auth/[...nextauth].ts
, give it a Knex.js
database connection, and set it as the adapter
in your NextAuth()
configuration.
import { KnexAdapter } from "authjs-knexjs-adapter";
import knex from "knex";
import NextAuth from "next-auth";
const db = knex({
client: "mysql2",
connection: {
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT ?? "3306", 10),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
},
});
export default NextAuth({
adapter: KnexAdapter(db),
providers: [ /* your providers */ ],
});
Import the adapter into src/hooks.server.js
, give it a Knex.js database
connection, and set it as the adapter
in your SvelteKitAuth
configuration.
import { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } from '$env/static/private';
import { KnexAdapter } from 'authjs-knexjs-adapter';
import { SvelteKitAuth } from '@auth/sveltekit';
import knex from "knex";
const db = knex({
client: 'mysql2',
connection: {
host: DB_HOST,
port: parseInt(DB_PORT ?? '3306', 10),
user: DB_USER,
password: DB_PASSWORD,
database: DB_DATABASE
}
});
export const handle = SvelteKitAuth({
adapter: KnexAdapter(db),
providers: [ /* your providers */ ],
});
Auth.js requires a specific database schema. There are two options provided here to create this schema:
Use either option or create the database schema some other way.
Note: These files are configured for MariaDB. They may work out-of-the-box with other database engines, or you may need to modify them according to your application.
The MIT License
Copyright 2023 Travis Horn
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
An adapter for Auth.js/NextAuth.js to allow you to connect to any database service via Knex.js.
The npm package authjs-knexjs-adapter receives a total of 3 weekly downloads. As such, authjs-knexjs-adapter popularity was classified as not popular.
We found that authjs-knexjs-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.