Beta

Quickstart

JS Frontend SDK

Before continuing

Make sure you have:


CakeAuth JavaScript frontend SDK is a wrapper which exposes the CakeAuth Frontend APIs. You can use it to build on top of your application.

If you're not into using an SDK, you can also use the CakeAuth Frontend APIs directly.

Installation

npm install @cakeauth/frontend

Usage

To start using the SDK, you can initiate a new instance of the CakeAuth class:

import { CakeAuth } from "@cakeauth/frontend";
 
const cakeauth = new CakeAuth({
  publicKey: process.env.CAKEAUTH_PUBLIC_KEY,
});

Adjust the approach of reading the public key from your .env file accordingly. In this example, we're using process.env to read the public key & your app url.

To better organize the APIs, all the "endpoints" are mounted under the CakeAuth's client object. For example, to read your environment settings, you can use the cakeauth.settings.list method:

const settings = await cakeauth.settings.list();

You can find the full list of available methods in the Frontend SDK reference.

What's next?

TODO:

  • Add more auth options
  • protect pages/components
  • protect API routes
  • session management
  • more on sdk reference

Last updated on

On this page