useSignature
A custom React hook to fetch digital signature from your backend for on-chain access control.
To make use of this hook, you must set up an endpoint which takes an address string as a query parameter and returns a digital signature along with an expire timestamp. A reference implementation can be found here.
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 beundefined
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 beundefined
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