Issue with @velo/wix-http-functions-hmac-authentication-backend: Cannot Find Module & Help with HMAC Authentication

Hi Wix Community,

I’m working on setting up HMAC authentication for a PUT request in an HTTP function on my Wix site. The goal is to securely update an item’s shelfLocation in the MembersCollection based on a PUT request, while ensuring the request is validated using HMAC.

Here’s the code I’m working with:

import { wixData } from 'wix-data';
import { getSecret } from 'wix-secrets-backend';
import { validateAuth } from '@velo/wix-http-functions-hmac-authentication-backend';

export async function put_updateShelf(request) {
    const body = await request.body.json();
    const { itemId, shelfLocation } = body;

    const response = {
        headers: {
            "Content-Type": "application/json",
        },
        body: "",
    };

    try {
        // Validate the request using HMAC authentication
        await validateAuth(request, { secretName: "HMAC_SECRET" });

        // Check for missing parameters
        if (!itemId || !shelfLocation) {
            response.body = JSON.stringify({ message: "Missing itemId or shelfLocation" });
            return {
                status: 400,
                body: response.body,
                headers: response.headers
            };
        }

        // Update the shelfLocation in the MembersCollection
        const updatedItem = await wixData.update("MembersCollection", { _id: itemId, shelfLocation });

        // Return success response
        response.body = JSON.stringify({ message: "Shelf location updated successfully", item: updatedItem });
        return {
            status: 200,
            body: response.body,
            headers: response.headers
        };
    } catch (err) {
        // Handle HMAC failure or other errors
        response.body = JSON.stringify({ message: "Invalid HMAC signature or failed to update: " + err.message });
        return {
            status: 400,
            body: response.body,
            headers: response.headers
        };
    }
}

Problem:

The issue I’m facing is with the following line:

import { validateAuth } from '@velo/wix-http-functions-hmac-authentication-backend';

I’m getting this error: Cannot find module ‘@velo/wix-http-functions-hmac-authentication-backend’ or its corresponding type declarations.

What I’ve Tried:

  1. I followed the official Wix HMAC authentication documentation.
  2. The HMAC secret is stored in the Wix Secrets Manager under the name HMAC_SECRET.
  3. I ensured that the endpoint logic itself works without the HMAC validation part, so I’m certain that the issue is with importing and using validateAuth.

Request for Help:

  • Does anyone know if there is an additional setup required to use @velo/wix-http-functions-hmac-authentication-backend?
  • Has anyone faced this issue or successfully implemented HMAC authentication using this package?
  • Is there a workaround or a different way to handle HMAC validation if this package isn’t available?

Any help or advice would be greatly appreciated!

Thanks in advance!

Hi! Did you install the velo package?

If yes, I would run the code to see if it works or not as well in case the error is in the editor but not affecting the code

1 Like