Skip to main content

3. Exposing Auth APIs

We will add all the backend APIs for auth on /auth/*. This can be changed by setting the apiBasePath property in the appInfo object on the backend and frontend. For the rest of this page, we will assume you are using /auth/*.

Create a new file auth.js#

  • An example of this can be found here.
auth.js
let supertokens = require("supertokens-node");let { middleware } = require("supertokens-node/framework/awsLambda");let { getBackendConfig } = require("./config");let middy = require("@middy/core");let cors = require("@middy/http-cors");
supertokens.init(getBackendConfig());
module.exports.handler = middy(middleware()).use(cors({    origin: getBackendConfig().appInfo.websiteDomain,    credentials: true,    headers: ["Content-Type", ...supertokens.getAllCORSHeaders()].join(", "),    methods: "OPTIONS,POST,GET,PUT,DELETE"})).onError(request => {    throw request.error;});
important

Notice that we called supertokens.init above. We will need to call this in all API endpoints that use any functions related to supertokens.