Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

authjs-knexjs-adapter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authjs-knexjs-adapter

An adapter for Auth.js/NextAuth.js to allow you to connect to any database service via Knex.js.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-84.21%
Maintainers
1
Weekly downloads
 
Created
Source

Auth.js Knex.js Adapter

An adapter for Auth.js/NextAuth.js to allow you to connect to any database service via Knex.js.

Installation

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

Next.js

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 */ ],
});

SvelteKit

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 */ ],
});

Database Schema

Auth.js requires a specific database schema. There are two options provided here to create this schema:

  • A Knex.js migration file
  • A schema dump SQL file

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.

License

The MIT License

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

Keywords

FAQs

Package last updated on 23 Jan 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc