Skip to main content

Auth

caution

This is the SST v1.x Constructs doc. SST v2 is now released. If you are using v2, see the v2 Constructs doc. If you are looking to upgrade to v2, check out the upgrade steps.

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

cdk.id?

Type : string

Allows you to override default id for this construct.

Properties

An instance of Auth has the following properties.

id

Type : string

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(stack, {
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(stack, {
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(stack, {
api,
prefix: "/custom/prefix"
})