Edit this page

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

Copy
Copied
class UAuthConnector extends AbstractConnector {
  constructor(public options: UAuthConnectorOptions) {}
}

const uauthConnector = new UAuthConnector(options);

registerUAuth()

Assigns pkg to UAuthConnector.UAuth.

Copy
Copied
static registerUAuth(pkg: typeof UAuth): void

importUAuth()

Dynamically imports UAuth and assigns it to UAuthConnector.UAuth.

Copy
Copied
public static async importUAuth(): Promise<void>

callbackAndActivate()

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

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

uauth

Returns the local UAuth instance.

Copy
Copied
public get uauth(): UAuth

subConnector

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

Copy
Copied
public get subConnector(): AbstractConnector & {
  isAuthorized?(): Promise<boolean>
}

UAuthConnectors

Copy
Copied
interface UAuthConnectors {
  injected: AbstractConnector
  walletconnect: AbstractConnector
}

UAuthConnectorOptions

The options object passed to the UAuthConnector constructor.Type

Copy
Copied
interface UAuthConnectorOptions
  extends AbstractConnectorArguments,
    Partial<UAuthConstructorOptions> {
  uauth?: UAuth
  connectors: UAuthConnectors
  shouldLoginWithRedirect?: boolean
}

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.

Copy
Copied
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

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