useSignature

A custom React hook to fetch digital signature from your backend for on-chain access control.

Usage

import { useSignature } from "authento-react";
  
export const MyComponent = () => {
  const { refetch: getSignature } = useSignature({
    endpoint: "https://api.example.com/signature",
    onSuccess: (expireTs, signature) => {
      console.log({ expireTs, signature });
    },
    onError: (error) => {
      console.log(error);
    },
  }); 

  return (
    <div>
      <button onClick={refetch}>Generate Signature</button>
    </div>
  );
};

Configuration

The useSignature hook accepts a configuration object with the following options:

  • endpoint (required): Your own endpoint for digital signature.

  • onSuccess (optional): This function will fire when the digital signature is fetched successfully

  • onError (optional): This function will fire when the signature request encounters an error.

Return Value

The useSignature hook returns an object with the following properties:

  • signature: A string representing the digital signature generated. It will be undefined initially and will be updated with the fetched signature when available.

  • expireTs: A number representing the Unix timestamp (in seconds) used to generate the digital signature. It will be undefined initially and will be updated with the fetched value when available.

  • refetch: A function that can be called to manually trigger a refetch of the digital signature.

Last updated