Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP PATCH - Unauthorized Error #29

Open
drveresh opened this issue Aug 20, 2024 · 2 comments
Open

HTTP PATCH - Unauthorized Error #29

drveresh opened this issue Aug 20, 2024 · 2 comments

Comments

@drveresh
Copy link

I am getting the below error with the EdgeFunction (EF) when trying to update a table of SQLite database instance. The error indicates neither a real technical issue nor a meaningful(unauthorized) issue. Please clarify and address this issue asap, I'm blocked on this.

{
    "error": {
        "status": "401",
        "title": "Unauthorized",
        "detail": "PATCH /v2/functions/myFunction was unauthorized"
    }
}

Below is the EF code:

if ( request.method === "PATCH" ) {
        const query = putQuery(request); //Returns "UPDATE Temp set status='${status}' WHERE id=${id}"
        result = await connection.sql(query);
        message = `Number of updates: ${result.length}`;
}

In the Console Logs, it is definitely a PATCH type request created via local POSTMAN app.

@TizianoT
Copy link
Collaborator

@drveresh
Authorization
When creating an edge function, you have the option to assign an API key to it.

If an API key is assigned, any calls to the edge function will automatically authenticate access to the associated database using that API key.

If you choose not to assign an API key, you will need to provide it when invoking the edge function. The API key can be included in the request as a query parameter named "apikey" or within the body.

For more information, you can refer to this discussion about securing edge functions with an API key.

Executing
When executing an edge function, you should use either the GET or POST methods, depending on whether you need to include a request body.

The specific actions performed by the edge function are independent of the HTTP method used. The typical REST method conventions do not apply to edge functions in this context. You can think of an edge function as a piece of code that runs close to your database and can perform any operation you define. You trigger this code using a GET or POST request.

Within your edge function, you can access:

  • Query parameters via request.params
  • The request body via request.data

@drveresh
Copy link
Author

Got it, thanks for the clarification. Please update the documentation accordingly, or else users will assume the same.

Also, please update those error messages to convey the appropriate reason, else it is confusing allot similar to other error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants