Setup
For an easy way to get started testing the SDK, use our testing page where you can enter your app secret, login, and then make requests in the browser console.
Installation
To install and set up the library, run:
Or if you prefer using Yarn:
Just want to
Reference the SDK
You can reference the SDK in two ways:
OR
Instantiate the SDK
You can instantiate the SDK with your app secret, or with a base URL. Only use your app secret server side in a production environment. Client requests should be sent to a proxy server. To set up a proxy server for your app, you can use our open source Express.js server or our Sample App as a starting point.
Or
You can also instantiate the SDK via CDN in an HTML file.
Make a Request
As a first request, use your appId and call getApp.
By default, handlers return the payload and will throw Errors. You can get the raw response by calling the raw handler as shown below:
The raw handlers can be useful in situations where more data from the response is required. However, it can still throw an error, to fix that we can call the safe handler as shown below:
Login a User
Logging in a user is as simple as:
This will trigger a prompt for the user to sign-in. You can skip the email prompt by providing an email like so:
You can also directly pass in a did token (unregistered). With this method you can await the response:
When not passing a didToken, you must rely on a callback. To handle a successful login you have to pass in an onSuccess handler:
Note that you must use a web browser or similar environment for authentication.
Logout a User
Handling an active session
Using initialize, you can sign in a user if there's already an active session:
This will return whether or not the user was successfully logged in. You can also pass it an onComplete handler:
Request Details
By default, handlers return the payload and will throw Errors. You can get the raw response by calling the raw handler as shown below:
The raw handlers can be useful in situations where more data from the response is required. However, it can still throw an error, to fix that we can call the safe handler as shown below:
Some endpoints may have different return types depending on the provided properties. For this reason, there are more specific handlers available:
These all call the same core endpoint (https://api-v2.assetlayer.com/api/v1/app/info), but getApp & getApps offer stricter type security when passing props and returning values. Typescript is highly recommended and the sdk includes extensive typings, useful for referencing & importing, allowing for turn-key type-safe app development.
Last updated