npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terra-money/login-sdk

v1.0.3

Published

Simple package to resolve requests to Login API.

Downloads

10

Readme

This repository is a simple package that allows frontend devs to interact with the Terra Login API, by fetching and posting any type of stringified information.

Usage

This package should be accompanied by:

"@dynamic-labs/sdk-react-core": "x.x.x",

And then optionally by any of the following chains that the frontend might want to support.

"@dynamic-labs/solana": "x.x.x",
"@dynamic-labs/cosmos": "x.x.x",
"@dynamic-labs/ethereum": "x.x.x", # EVMs

Basic Example

The login functionality is supported by a Provider that should wrap around the components that need to interact with the Terra Login API.

It should always be supplied with an environmentId and a list of wallet connectors that the frontend wants to support.

The core functionality of the login provider is the eventsCallbacks field, which allows the frontend to define custom behavior for events that happen during the login process.

Below is an example of setting a callback function for the onAuthSuccess event, which is triggered when the user successfully logs in. In this case, after a user logs in, the frontend will use this package to login into our API, and then use the token we return to fetch the user's session information.

import { getLoginAuthToken, getPulsarUserInfo } from '@terra-money/login-sdk'

import { CosmosWalletConnectors } from '@dynamic-labs/cosmos'
import { SolanaWalletConnectors } from '@dynamic-labs/solana'
import { EthereumWalletConnectors } from '@dynamic-labs/ethereum'
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core'

<DynamicContextProvider
    settings={{
    eventsCallbacks: {
        onAuthSuccess: async (args) => {
        const { authToken } = args
        const loginToken = await getLoginAuthToken(authToken)
        const userInfo = await getEnterpriseUserInfo(loginToken)
        const session = JSON.parse(userInfo)
        // Do something with the session here
        },
    },
    environmentId: 'your-environment-id',
    walletConnectors: [
        CosmosWalletConnectors,
        SolanaWalletConnectors,
        EthereumWalletConnectors,
    ],
    }}
>
    {children}
</DynamicContextProvider>

Documentation for DynamicContextProvider can be found here, to see additional props that can be passed to the Provider, which include fields that allow filtering of available wallets to login, set logo images, and more.

Additional documentation for the eventsCallbacks field can be found here.

After setting up the provider, the DynamicWidget button can be placed anywhere in the app to trigger the login process.

import { DynamicWidget } from '@dynamic-labs/sdk-react-core'

<DynamicWidget />

These two components are the only ones needed to set up the login functionality in a frontend app. The DynamicWidget button will trigger the login process, and the DynamicContextProvider will handle the login events and provide the frontend with the necessary information to interact with the Terra Login API.

When a user logs in, this information is persisted in the browser, but onAuthSuccess is only triggered once, at the moment of login. If after that, you want to fetch the user's authToken again, you can use the getAuthToken function from the @dynamic-labs/sdk-react-core package.

import { getAuthToken } from '@dynamic-labs/sdk-react-core'

const authToken = getAuthToken()

Additional hooks exist to interact with the Provider, such as useIsLoggedIn and useUserWallets, which can be used to check if a user is logged and to get the wallets that the user has connected, respectively.