Authentication

Reference

This page explains the low level functions exposed by the library and is intended for advanced users and curious minds. In most cases you'll be leveraging the library through the generated code that wraps these functions and exposes a higher level API in the form of a express route handler.

Importing the library

import {init, handleRequest} from '@subzerocloud/auth';

Initializing the library

The init function takes 3 parameters:

  • a database client (pg.Client) that will be used to run queries against the database
  • a nodemailer compatible object that will be used to send emails
  • a log function that will be used to log messages ( you'll probably want to log only in debug mode )
import pg from 'pg';
const { Client } = pg;
import nodemailer from 'nodemailer';
function logFn(m: string){ console.log('auth:', m);}
//...
await init(Client, nodemailer, logFn);

Handling requests

The handleRequest function takes 2 parameters:

  • a request object (http.IncomingMessage)
  • a response object (http.ServerResponse)
await handleRequest(req, res)

For a list of endpoint exposed by the library see here

Previous
Auth Library Overview