Andrew Mushel

UAuth Web3-React Library

The @uauth/web3-react library is a middleware library used for integrating UAuth with web3-react applications.

UAuthConnector

The UAuthConnector class is the default export of the @uauth/web3-react library.

constructor

class UAuthConnector extends Connector {
  constructor({actions, options, onError}: UAuthConnectorConstructorArgs) {}
}

const uauthConnector = new UAuthConnector(args);

registerUAuth()

Assigns pkg to UAuthConnector.UAuth.

static registerUAuth(pkg: typeof UAuth): void

importUAuth()

Dynamically imports UAuth and assigns it to UAuthConnector.UAuth.

public static async importUAuth(): Promise<void>

callbackAndActivate()

Calls the loginCallback() method of this.uauth and activates the connector using the activate argument.

async callbackAndActivate<T>(
  options: ConnectorLoginCallbackOptions,
): Promise<void>

uauth

Returns the local UAuth instance.

public get uauth(): UAuth

subConnector

Returns the connector used internally to connect to web3-react.

public get subConnector(): Connector & {
  isAuthorized?(): Promise<boolean>
}

UAuthConnectors

interface UAuthConnectors {
  injected: Connector
  walletconnect: Connector
}

UAuthConnectorConstructorArgs

The arguments object passed to the UAuthConnector constructor.

interface UAuthConnectorConstructorArgs {
  actions: Actions
  options: UAuthConstructorOptions & {
    uauth?: UAuth
    connectors: UAuthConnectors
    shouldLoginWithRedirect?: boolean
  }
  onError?: (error: Error) => void
}

options.shouldLoginWithRedirect

If shouldLoginWithRedirect is set to true, the uauthConnector instance will use the login() method instead of the default, loginWithPopup().

Then you must set up a callback page for the authorization server to redirect back to.

import {uauth} from './connectors'

// On page load...

const {activate} = useWeb3React()

useEffect(() => {
  uauth
    .callbackAndActivate({activate})
    .then(() => {
      // Redirect to success page
    })
    .catch(error => {
      // Redirect to failure page
    })
}, [])

ConnectorLoginCallbackOptions

interface ConnectorLoginCallbackOptions {
  url?: string
  activate: (
    connector: Connector,
    onError?: (error: Error) => void,
    throwErrors?: boolean,
  ) => Promise<void>
  onError?: (error: Error) => void
  throwErrors?: boolean
}