npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

knex-masto-auth

v1.0.1

Published

Mastodon authentication integrated with knex storage

Readme

Knex Masto Auth

Mastodon authentication using a knex instance for data persistance. Automatically registers a client with previously unknown instances and persists them to your database for future use.

import KnexMastoAuth, { migrate } from 'knex-masto-auth';
import Knex from 'knex';

// Bring your own knex instance
const db = new Knex({
	client: 'sqlite3',
  connection: {
    filename: './db.sqlite3',
  },
});

// Create the database tables if they're absent (idempotent operation)
await migrate(db);

// Get the instance of MastoAuth
const auth = new KnexMastoAuth(db, {
	clientName: 'My App',
	redirectUri: 'http://my-app.example/exchange-token'
});


// Example server - for full details of how to use the `auth` instance, see the [masto-auth library](https://gitlab.com/paulkiddle/masto-auth#module_masto-auth.default)
export default async (req, res) => {
	const { pathname, searchParams } = new URL('file://' + req.url);

	if(pathname === '/login') {
		// Get the instance to login to, e.g. through form submission
		const instance = searchParams.get('instance') || 'https://kith.kitchen';

		// Get the redirect URL - this will also handle issuer lookup and client registration if needed
		const instanceAuthPage = await auth.getRedirectUrl(instance);

		// Redirect to instance log in page
		res.setHeader('location', instanceAuthPage);
		res.statusCode = 303;
		res.end();
	} else if(pathname === '/exchange-token') {
		// User will be redirected here after authentication
		// Get the user info and do what you want with it
		res.end(JSON.stringify(await auth.getUserFromCallback(req)))
	} else {
		res.statusCode = 404;
		res.end('Not found');
	}
}

Dependencies

  • knex-settings: ^2.0.1
  • masto-auth: ^1.1.0

knex-masto-auth

Knex Masto Auth

See: default

knex-masto-auth.default

Kind: static class of knex-masto-auth

new module.exports(knex, clientOptions)

Create a new instance of KnexMastoAuth

| Param | Type | Description | | --- | --- | --- | | knex | Knex | Instance of the Knex library | | clientOptions | Object | Client options | | [options.catchError] | function | Optional function to call when an error occurs in the client registration process | | [options.tableName] | function | Name of the sql table to use to store mastodon client data. Defaults to 'mastodon_clients' |

default.migrate(knex) ⇒ MastoAuth

Create the storage table if it doesn't exist and return a new instance of KnexMastoAuth

Kind: static method of default

| Param | Type | Description | | --- | --- | --- | | knex | Knex | Instance of the Knex library | | [options.catchError] | function | Optional function to call when an error occurs in the client registration process | | [options.tableName] | function | Name of the sql table to use to store mastodon client data. Defaults to 'mastodon_clients' |

knex-masto-auth.migrate()

Create the storage table if it doesn't exist

Kind: static method of knex-masto-auth
See: module:knex-masto-auth.default#migrate

knex-masto-auth~ClientOptions

Kind: inner typedef of knex-masto-auth

| Param | Type | Description | | --- | --- | --- | | redirectUri | string | The URI to redirect the user to after they have authenticated on their mastodon instance. | | clientName | string | The name of your application |

knex-masto-auth~CatchError : function

Kind: inner typedef of knex-masto-auth

| Param | Type | Description | | --- | --- | --- | | error | Error | The error that occured | | url | string | The issuer URL that the error occured for |

knex-masto-auth~Knex

Instance of the knex library

Kind: inner external of knex-masto-auth
See: https://knexjs.org/

knex-masto-auth~MastoAuth

Instance of the MastoAuth library

Kind: inner external of knex-masto-auth
See: https://gitlab.com/paulkiddle/masto-auth#module_masto-auth.default