saaslet.js

saaslet

Creating an Instance

Initialises an instance of saaslet.js. This is a pre-requisite for all other steps.

const saaslet = new Saaslet( appPublishableKey, apiUrl );
  • appPublishableKey string

    Each app has a publishable and a secret key that identifies it to the Saaslet API - you can find yours in the dashboard for your app].

  • apiUrl optionalstring

    By default, all requests to Saaslet go to https://api.saaslet.com. But to allow for cookie-sharing, requests need to pass through your own domain, either via a CNAME record in your DNS or via a proxy endpoint (ou can learn more about how to do this here).

    Whichever method you choose, you can tell saaslet about your endpoint here, e.g. 'https://saaslet-api.mydomain.com' or 'https://mydomain.com/saaslet-proxy'.

Subscribing to Events

Your saaslet instance emits events whenever a user signs up, pays, logs in or out etc. Using this method you can subscribe to these events.

saaslet.on( eventName, callback, context )
  • eventName string

    The name of the event, e.g. 'login' or 'signup'. Please find a detailed list of emitted events as part of the method descriptions below.

  • callback function

    The callback function that will be invoked whenever the event occurs.

  • context optionalobject

    An optional context the callback function will be invoked with - usually this. This gets around the need to pass methods with .bind(this) or to keep references to unsubscribe later.

Unsubscribing from Events

This deregisters a callback function that was previously registered for a given event

saaslet.off( eventName, callback, context )
  • eventName string

    The name of the event, e.g. 'login' or 'signup'.

  • callback function

    The callback function that was previously registered for that event.

  • context optionalobject

    Optional - if you've added a context when subscribing before, you need to pass it in here to unsubscribe this particular combination of context, callback and eventname.

Creating a Widget

Create a signup, login, payment or other kind of Saaslet widget. This method returns an instance of Widget (see below).

saaslet.createWidget( widgetName, elementOrSelector, widgetConfig, widgetCss )
  • widgetName string

    The name of the widget. Currently supported names are 'signup-login' and 'payment'.

  • elementOrSelector functionstring

    A DOM element or a string selector that can resolve to an existing DOM element the widget should be rendered into.

  • widgetConfig optionalobject

    Pretty much every aspect of your widget can be freely configured. To do so, head over to https://saaslet.com/app/#/widgets/signup-login and copy/paste the resulting configuration here.

  • widgetCss optionalstring

    A CSS String to style your widget. To create your styles head over to https://saaslet.com/app/#/widgets/signup-login and copy/paste the resulting CSS here.

Example

const loginWidget = saaslet.createWidget( 'signup-login', document.getElementById( 'widget-container'), { companyName: "Example Enterprises" }, `.saaslet-signup-login .saaslet-header h2 { color:red; }` ); // Change configuration at runtime if( navigator.language.startsWith( 'de' ) ) { loginWidget.setConfig({ loginButtonText: 'einloggen' }); } // Change Styles at runtime loginWidget.setCss( '*{ font-family: Roboto, sans-serif; }' ); // Destroy the widget loginWidget.destroy();

widget

Set Widget Config

Update a widget's configuration after its been initialized

widget.setConfig( config )

Set Widget CSS

Update a widget's CSS after its been initialized

widget.setCss( css )

Set Widget Size

If the element you've created the widget in is sufficiently big, your widget will automatically adjust to its size. To set a different size, use this method (or CSS for your container element).

widget.setSize( width, height )
  • width number

    This desired width of your widget in pixels

  • height number

    This desired height of your widget in pixels

Destroy widget

Destroys the widget and removes it from the DOM

widget.destroy();

user

Sign a user up

Registers a new account for your app.

saaslet.user.signup( email, password )
  • email string

    The user's email

  • password string

    This user's password

  • returns promise userId promise

    Returns a Promise that will resolve to the new user's id.

Log a user in

Creates a session for a registered user

saaslet.user.login( email, password )
  • email string

    The user's email

  • password string

    This user's password

  • returns promise userId promise

    Returns a Promise that will resolve if the login was succesful or reject with an error.

Log a user out

Terminates an existing session

saaslet.user.logout()
  • email string

    The user's email

  • password string

    This user's password

  • returns promise userId promise

    Returns a Promise that will resolve if the login was succesful or reject with an error.

Check if the user is logged in

A simple check to see if a user has an active session. Returns a Promise that will resolve with true or false.

saaslet.user.isLoggedIn()
  • returns promise userId promise

    Returns a Promise that will resolve with true or false.

Get Session Details

Returns email, id and plan subscriptions for a logged in user.

saaslet.user.getInfo()
  • returns promise sessionDetails promise

    Returns a Promise that will resolve to a map with email, id and subscriptions.

Set a value

An easy mechanism to store user-specific settings, e.g. language preferences, layout configurations etc.

saaslet.user.set( key, value )
  • key string

    The key to store the value under. E.g. 'last-document', 'language', 'show-hints-at-startup' etc.

  • value string

    Any kind of value

  • returns promise success promise

    Returns a Promise that will resolve if the value was succesfully stored.

Get a value

Retrieves a user specific value that was previously stored using saaslet.user.set()

saaslet.user.get( key )
  • key string

    The key the value has previously been stored under.

  • returns promise value promise

    Returns a Promise that will resolve to the value.

Get all values

Retrieves a key-value map of all data stored for that user.

saaslet.user.get( key )
  • returns promise value promise

    Returns a Promise that will resolve to the map.

Change email

Updates the email for a logged in user.

saaslet.user.changeEmail( email, password )
  • email string

    The new email address for this user.

  • password string

    The current password for that user for security reasons.

  • returns promise success promise

    Returns a Promise that will resolve if the email was changed succesfully.

Change password

Updates the password for a logged in user.

saaslet.user.changePassword( oldPassword, newPassword )
  • oldPassword string

    The current password for the user

  • newPassword string

    The new password for the user

  • returns promise success promise

    Returns a Promise that will resolve if the password was changed succesfully.

on this page: