UAuth BNC-Onboard Library
The @uauth/bnc-onboard
package is a deprecated middleware library used for integrating UAuth with Blocknative BNC Onboard applications. For the latest Blocknative Web3-Onboard module, see @web3-onboard/uauth.
UAuthBNCOnboard
The UAuthBNCOnboard
class is the default export for @uauth/bnc-onboard
.
export default class UAuthBNCOnboard {
constructor
constructor(public options: ConstructorOptions)
UAuth
A reference to the UAuth library. Used to construct a UAuth instance if one isn't passed to the constructor.
public static UAuth: typeof UAuth
registerUAuth()
Registers an imported @uauth/js
package as UAuthConnector.UAuth.
public static registerUAuth(pkg: typeof UAuth): void
importUAuth()
Dynamically imports UAuth and assigns it to UAuthConnector.UAuth.
public static async importUAuth(): Promise<void>
get uauth()
Gets the local UAuth instance.
public get uauth(): UAuth
getUAuth()
Calls UAuthBNCOnboard.importUAuth and gets the local UAuth instance.
public async getUAuth(): Promise<UAuth>
callbackAndWalletSelect()
Calls this.uauth.loginCallback
and selects a wallet using onboard instance.
public async callbackAndWalletSelect(
options: CallbackOptions,
): Promise<boolean>
module()
Creates a wallet module used to instantiate an Onboard instance
public module({preferred = true, walletconnect}: ModuleOptions): WalletModule}
shouldLoginWithRedirect
If shouldLoginWithRedirect
is set to true
in the ConstructorOptions
used to instantiate UAuthBNCOnboard
, then you must set up a callback page for the authorization server to redirect back to.
import onboard from './onboard'
import uauthOnboard from './uauthOnboard'
// On page load...
uauthOnboard
.callbackAndWalletSelect({onboard})
.then(() => {
// Redirect to success page
})
.catch(error => {
// Redirect to failure page
})
Caching Wallets
Blocknative has documentation about caching wallets. The example code won't quite work out of the box because the bnc-onboard
library doesn't know if the token from the last login session is still valid. To fix this, you need to check before selecting the Unstoppable wallet.
const previouslySelectedWallet = window.localStorage.getItem('selectedWallet')
if (previouslySelectedWallet != null) {
// We check to see if the last connected wallet was the Unstoppable one.
if (previouslySelectedWallet === 'Unstoppable') {
// If it is then we try to retrieve the user and select the wallet.
// Otherwise we don't try to reconnect.
await uauthOnboard
.getUAuth()
.then(async uauth => {
await uauth.user()
await onboard.walletSelect('Unstoppable')
})
.catch(() => {
window.localStorage.removeItem('selectedWallet')
})
} else {
await onboard.walletSelect(previouslySelectedWallet)
}
}