Skip to main content

Auth

SST Auth is a lightweight authentication solution for your applications. With a simple set of configuration you can deploy a function attached to your API that can handle various authentication flows. Full documentation here

Constructor

new Auth(scope, id, props)

Parameters

AuthProps

authenticator

Type : string | Function | FunctionProps

The function that will handle authentication

Properties

An instance of Auth has the following properties.

SST_AUTH_PRIVATE

Type : Secret

Secret that contains the private JWT signing key

SST_AUTH_PUBLIC

Type : Secret

Secret that contains the public JWT signing key

Methods

An instance of Auth has the following methods.

attach

attach(scope, props)

Parameters

Attaches auth construct to an API

const api = new Api(stack, "Api", {});
const auth = new Auth(stack, "Auth", {
authenticator: "functions/authenticator.handler"
})
auth.attach({
api
})

ApiAttachmentProps

api

Type : Api

The API to attach auth routes to

const api = new Auth(stack, "Api", {});
const auth = new Auth(stack, "Auth", {
authenticator: "functions/authenticator.handler"
})
auth.attach({
api
})

prefix?

Type : string

Default : "/auth"

Optionally specify the prefix to mount authentication routes

const api = new Auth(stack, "Api", {});
const auth = new Auth(stack, "Auth", {
authenticator: "functions/authenticator.handler"
})
auth.attach({
api,
prefix: "/custom/prefix"
})