Quickstart
Installation
Install Authora using your package manager of your choice.
npm install authora
Initialize Authora
Import Authora
and initialize it with your adapter(if you are using session). Refer to the Database page to learn how to set up your database and initialize the adapter. Make sure you configure the sessionCookie/JWT
option and register your Authora
instance type.
import { Authora } from "authora";
const adapter = new BetterSQLite3Adapter(db); // your adapter
export const authora = new Authora(adapter, {
sessionCookie: {
attributes: {
// set to `true` when using HTTPS
secure: process.env.NODE_ENV === "production"
}
}
});
export const authora = new Authora({
useJWT: true,
jwtSecret: process.env.JWT_SECRET,
// the jwt option can be overide later
jwtOptions: {
signOptions: {
expiresIn: '1h'
}
}
});
// IMPORTANT!
declare module "authora" {
interface Register {
Authora: typeof authora;
}
}
Polyfill
If you're using Node.js 18 or below, you'll need to polyfill the Web Crypto API. This is not required in Node.js 20, CloudFlare Workers, Deno, Bun, and Vercel Edge Functions. This can be done either by importing webcrypto
, or by enabling an experimental flag.
import { webcrypto } from "node:crypto";
globalThis.crypto = webcrypto as Crypto;
node --experimental-web-crypto index.js
Last updated