Connect Javascript SDK
The Connect JavaScript SDK makes it easy to integrate Connect into your application, enabling users to effortlessly sign in or sign up.
⚠️
This guide assumes that all prerequisite steps mentioned in the Connect tutorial have been applied and configured.
Installation
npm install --save @portabl/js-connect-with-portabl
Create the client
Initialize the client with an accountId
and the respective domains for the environment.
const connectClient = new ConnectClient({
accountId: '<PORTABL_ACCOUNT_ID>',
connectDomain: 'https://api.getportabl.com',
walletDomain: 'https://wallet.getportabl.com',
});
Sign In / Sign Up
To initiate a login attempt that creates a new user if one doesn't already exist, call loginWithRedirect.
document.getElementById('login').addEventListener('click', async () => {
await connectClient.loginWithRedirect();
});
window.addEventListener('load', async () => {
await connectClient.handleRedirectCallback();
// Connection established. Now make a call to get the access token.
const { access_token } = await connectClient.getAccessToken();
});
Check if the user is authenticated
To check if the user is authenticated, use the getIsAuthenticated()
method.
const isUserAuthenticated = await connectClient.getIsAuthenticated()
Sign out
To sign out a user, call logout()
.
connectClient.logout()
Options
Option | Type | Default | Description |
---|---|---|---|
accountId | string | Your account ID | |
connectDomain | string | The domain for accessing the Connect API | |
walletDomain | string | The domain of the Portabl wallet |