-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Improve code examples in Workers basic auth documentation #27822
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
base: production
Are you sure you want to change the base?
Conversation
- Fixed TypeScript type annotations for request and env parameters - Improved Rust code safety with bounds checking before array access - Added proper error handling for base64 decoding in Rust - Replaced unsafe unwrap() calls with match expressions - Fixed non-idiomatic Rust comparisons (is_none(), is_empty()) - Added note about timing-safe comparison in Rust example - Overall quality improvement: 87% -> 95%
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
- Added Env interface definition with MY_DURABLE_OBJECT binding - Added WranglerConfig component showing Durable Object binding setup - Improved full executability: users can now copy and run the example - Overall quality improvement: 86% -> 100%
- Fixed syntax error: function\* → function* (line 32) - Fixed style guide violations: 4 backticks → 3 backticks (lines 110, 122) - Removed empty code blocks at end of file (lines 132-134) Reviewed 1 file with 3 code blocks Fixed 3 issues identified in code review
| await new Promise((resolve) => setTimeout(resolve, 1_000)); | ||
| } | ||
| let counter = 0; | ||
| while (!signal.aborted) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting and indentation is all off
elithrar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sent you feedback internally
Code Review Summary
This PR improves code example quality in
/workers/examples/basic-authbased on systematic review.Overall Results:
Examples Improved
TypeScript Example (Lines 152-259)
request: Requestandenv: Envparameters. TypeScript now compiles without errors.Before:
After:
Rust Example (Lines 263-333)
Issues Fixed:
.unwrap()on base64 decode with match expressionauthorization == Nonetoauthorization.is_none()encoded == ""toencoded.is_empty()splitn(2, ':')and added bounds checkBefore (unsafe):
After (safe):
Review Methodology
Detailed Review Results
This review used a systematic framework that:
Scoring Guide:
Issue Levels:
JavaScript Example
TypeScript Example (Before fixes)
TypeScript Example (After fixes)
Rust Example (Before fixes)
Rust Example (After fixes)
Hono Example
Impact
These improvements ensure:
All examples now represent high-quality, safe, and usable code for developers learning Workers authentication patterns.