Home > @lukso/data-provider-base > AuthenticatedFormDataUploader
This is a custom data provider that uses a pre-shared token to sign a short lived jwt token and send it as a bearer token to the endpoint. On the server side you can then verify the token using this kind of code:
Signature:
declare class AuthenticatedFormDataUploader extends BaseFormDataUploader
Extends: BaseFormDataUploader
try {
// Otherwise let's validate the token.
const { exp } = verify(token, env.JWT_SECRET);
// Tokens cannot be expired or have a duration that's more than
// 600 seconds into the future.
if (exp < Date.now() / 1000 || exp - Date.now() / 1000 > 600) {
// If the token is expired then it's no good
return new Response("Unauthorized", { status: 401, headers: cors });
}
} catch (error) {
console.error(error);
return new Response("Unauthorized", { status: 401, headers: cors });
}
and then forward the request to a pinata or other endpoint for the final upload.
Constructor | Modifiers | Description |
---|---|---|
(constructor)(gateway, sharedKey) | Create a new instance of the authenticated form data uploader. |
Method | Modifiers | Description |
---|---|---|
getEndpoint() | Return the endpoint to be used for the upload. | |
getRequestOptions(dataContent, meta) | Return the request options used for the fetch call. | |
getToken() | Exposed function in case this classes it used with an older ipfs-http-client implementation directly. |