Skip to content

Commit

Permalink
refactor: easyer check in api
Browse files Browse the repository at this point in the history
  • Loading branch information
jqshuv committed Oct 19, 2024
1 parent f80e4bb commit a40485e
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ function hasValidHeader(request: Request, env: Env): boolean {
// Get the Authorization header from the request.
const authHeader = request.headers.get('Authorization');

// Check if the Authorization header is valid.
if (authHeader === env.AUTH_SECRET) return true;

// Return false if the Authorization header is invalid.
return false;
// Return true if the Authorization header is valid.
return authHeader === env.AUTH_SECRET;
} else if (searchParams.has('auth')) {
// Get the auth query parameter from the request.
const authParam = searchParams.get('auth');

// Check if the auth query parameter is valid.
if (authParam === env.AUTH_SECRET) return true;

// Return false if the auth query parameter is invalid.
return false;
// Return true if the auth query parameter is valid.
return authParam === env.AUTH_SECRET;
} else {
return false;
}
Expand Down

0 comments on commit a40485e

Please sign in to comment.