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 Connector {
  constructor({ actions, options, onError }: UAuthConnectorConstructorArgs) {}
}

const uauthConnector = new UAuthConnector(args);

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(): Connector & {
  isAuthorized?(): Promise<boolean>
}

UAuthConnectors

Copy
Copied
interface UAuthConnectors {
  injected: Connector;
  walletconnect: Connector;
}

UAuthConnectorConstructorArgs

The arguments object passed to the UAuthConnector constructor.

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

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: Connector,
    onError?: (error: Error) => void,
    throwErrors?: boolean
  ) => Promise<void>;
  onError?: (error: Error) => void;
  throwErrors?: boolean;
}