Cedalio
Search
K

Authentication

In order to use the other methods, you must first log in. The process of logging in returns a JWT token that will be used to authenticate from that point onwards.
If you want to see more about how we handle authentication, check our Auth section

login

The SDK provides a method that logs you in behind the scenes and returns a valid JWT token. It will save it internally in the instance and use it to authenticate future API calls. Currently, JWT tokens last 30 minutes, after which all authenticated methods will return 401 and you will have to execute this method again.
This method will only run in a Browser environment. Otherwise it will throw a runtime error.

Example

const response = await cedalioSdk.login({ address: 'The wallet address' });

Parameters

  • address (string): The wallet address of the user interacting with the SDK.
  • provider (SupportedProviders): The Web3 Ethereum provider used to verify authentication against your wallet. This parameter is optional and rarely needed. By default Cedalio gets the provider from the window object, where the Wallet Extensions inject it. If you don't have a Wallet Extension like Metamask installed the login will fail unless you pass a valid provider.

Returns

Success
Error
{
ok: true,
status: 201,
data: { token: 'The JWT token' }
}
{
ok: false,
status: 401,
error: {
message: 'The server error',
payload: { /* Payload */ }
}
}

loginWithPrivy

Perform a Cedalio login using a Privy JWT token. Especially useful if you have a Privy integration in your front-end application.
This method runs both in Node and Browser environments

Example

const response = await cedalioSdk.loginWithPrivy({
address: 'The wallet address',
privyToken: 'The Privy JWT token'
});

Parameters

  • address (string): The wallet address of the user interacting with the SDK.
  • privyToken (string): The Privy JWT token.
Success
Error
{
ok: true,
status: 201,
data: { token: 'The JWT token' }
}
{
ok: false,
status: 401,
error: {
message: 'The server error',
payload: { /* Payload */ }
}
}

loginWithLens

Perform a Cedalio login using a Lens JWT token. Especially useful if you platform is integrated with Lens. This method was designed to be employed when you are operating in a backend environment and require a valid JWT to interact with our Gateway.
This method runs both in Node and Browser environments

Example

const response = await cedalioSdk.loginWithLens({
address: 'The wallet address',
lensToken: 'The Lens JWT token'
});

Parameters

  • address (string): The wallet address of the user interacting with the SDK.
  • lensToken (string): The Lens JWT token.
Success
Error
{
ok: true,
status: 201,
data: { token: 'The JWT token' }
}
{
ok: false,
status: 401,
error: {
message: 'The server error',
payload: { /* Payload */ }
}
}

logout

Removes the JWT token from the sdk instance. This method does not return anything.

Example

cedalioSdk.logout();

getAuthSession

Returns the JWT token used to authenticate against Cedalio after you login. In case the login hasn't been performed or the user has logged out, the token will be undefined. While the usage of the token to authenticate is used internally, this method is provided to allow the user to save it using localStorage or any state management strategy if needed.

Example

const session = cedalioSdk.getAuthSession();

Returns

Logged in
Logged out
{ token: 'Your token' }
{ token: undefined }

setAuthSession

Allows you to use an existing session. A session consists on a Cedalio JWT token obtained via one of the login methods or from the Studio under the Settings tab in the Access Tokens section by creating a new Access Token (which is a valid JWT token).setAuthSession is provided in case the user has stored a JWT token from a previous login response and prefers to use those values instead of requesting new ones or if you want to use an Access Token with a custom expiration time.

Example

cedalioSdk.setAuthSession({
token: 'Your token'
});

isLoggedIn

A helper method to check if the SDK is logged in.
This method will return true if it finds a token, even if the token has expired.

Example

const isLoggedIn = cedalioSdk.isLoggedIn();

Returns

A boolean value depending on if the token is present in the instance or not.