@tria-sdk/authenticate-web
The Tria Authentication SDK provides a simple way to integrate authentication into your web applications. It includes features such as login, account management, and interacting with smart contracts
Tria Authentication SDK
Installation
You can install the SDK using npm or yarn:
npm install @tria-sdk/authenticate-webyarn add @tria-sdk/authenticate-webUsage
Importing the AuthManager
First, import the AuthManager class from the SDK:
import { AuthManager } from '@tria-sdk/authenticate-web';Initializing the AuthManager
Create an instance of the AuthManager with the required options:
const authManager = new AuthManager({
analyticsKey: {
clientId : "string",
projectId : "string"
}
// Required: Provided by Tria
});the analytics key object is to be provided by tria. please request for your client id and project id from us.
Configuring the AuthManager
Configuration Options
Configuration options are blockchain related configurations. Sepolia is set as the default chain and the minimum required option is the chain.
The TriaConfigOptions interface allows you to configure the following properties:
chain [string]: The blockchain network (e.g., 'MUMBAI', 'POLYGON').environment [string]: The environment ('testnet' or 'mainnet').dappDetails [object]: An object containing your Dapp's domain and logo.aa [object]: Optional Anti-Addiction details.rpcUrl [string]: Optional RPC URL for the blockchain network.supportedChains [string array]: An array of strings containing the supported chains
UI Configuration Options [Login component]
These are the configuration options to customize the Login components UI. Ability to hide and display parts of the UI as well as change the text on certain parts of the login flow and the buttons as well.
Customizing the styles for the Login component
The css variables for the login component can be updated with the setAuthUIStyling method. An example is provided below along with the variables that can be changed and the default values that are currently set
Transactions UI Configuration Options [Approval popups]
These are the configuration options to customise the UI of the transaction popups, approval for signing message, sending transactions, minting NFTs approval and other relevant popups.
Wallet UI Configuration Options [Embedded Wallet]
These are the customisable properties for the embedded wallet. The wallet currently only has limited customization options. as of now switching between light mode and dark mode is possible and the primary color can be changed. This changes the glow color of the logo of the embedded wallet as well as the home page card background color when the wallet is open.
Using AuthManager Methods
Login
To prompt the user to log in, call the login method:
Validating the Session token
The session token is a unique token provided so that clients can verify the logged in user. this is unique to each user and generated on the backend. Upon login or signup a session token is returned from the login method so that the authenticated user can be validated. This token is short lived.
Logout
To log the user out, call the disconnect method:
Get Account
To get the user's account information, call the getAccount method:
This method returns an Account object with the following properties:
triaName: The user's Tria username.evm: An object containing the user's EVM-compatible address.nonEvm: An object containing the user's non-EVM-compatible address.
Check Authentication Status
To check if the user is authenticated, call the isAuthenticated method:
This method returns a boolean indicating whether the user is logged in.
Send Transaction
To send a transaction, call the send method with the amount, recipient address, and optional token address:
Sign Message
To sign a message, call the signMessage method with the message:
Write Contract
To write to a smart contract, call the writeContract method with the contract details and optional payment token:
Read Contract
To read from a smart contract, call the readContract method with the contract details:
Send NFT
To send an NFT, call the sendNft method with the recipient's Tria name and NFT details:
Approve
To approve a spender to spend an amount of user's erc20 token:
Check Token Allowance
To check allowance of a erc20 token for spender:
Broadcast Transaction
To broadcast a txnObject to a chain:
Get Bridge Quote (Refer connect sdk section for types)
To get a quote for a bridge txn and use the allowanceTarget and allowanceValue to check for allowance and approve the token:
Create a Bridge Transaction
To create a txn object for the bridge transaction:
Cancel Bridge Txn
To cancel a transaction using the orderId returned in the quote and create txn responses:
📝 Refer the connect sdk actions here for types and responses.
Event Listeners
You can listen to login and logout events by adding event listeners:
Removing Event Listeners
To remove an event listener, use the removeEventListener method:
Example
Here's an example of how you might use the Tria Authentication SDK in a web application:
CDN Usage
If you dont use npm as a package manager and want to simply use our cdn link to the package to use it on a static html page then follow the instructions below.
The cdn link for the package is as follows. It would be appropriate to use specific versions instead of @latest so as to keep breaking changes to a minimal if any. The package must be used inside a script tag declared as a module type. Please follow the provided example below. Examples for basic methods are provided. Further configurations are mentioned in the usage section of this document along with types, methods and parameters for the methods.
NuxtJS setup
If your NuxtJS is old (older than nuxt 3) and does not handle optional chaining parameters or nullish coalescing oeprators
create a file in your plugins folder named auth-manager.js
update your nuxt config
Example NuxtJS component as below. the auth manager should now be usable across your app
Last updated