D
Deno

help

Subhosting API protection

Ccosbgn1/22/2024
Is there a way to setup custom auth via some header for example for all subhosting routes? I.e. Deno will throw an error is Authorization!=="foo"?
DAHDeno AI Helper1/22/2024
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're looking to implement custom authentication for routes in a Deno application, using a header check for authorization. From your message, there seems to be a syntax error in the conditional check you've written. In JavaScript and TypeScript (which Deno uses), the strict equality operator is === rather than ==, and the negation operator is !==. Also, headers are typically accessed as properties of an object, so you would need to reference the header with the correct syntax. Here's a corrected version of the conditional check you might be aiming for:
if (request.headers.get("Authorization") !== "foo") {
// Throw an error or handle unauthorized access
}
if (request.headers.get("Authorization") !== "foo") {
// Throw an error or handle unauthorized access
}
Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of this advice. Additionally, ensure that you handle the request and response objects appropriately within the context of your Deno application, and that you're implementing proper security practices for authentication.

Looking for more? Join the community!