-
Notifications
You must be signed in to change notification settings - Fork 2
fix username/password auth #81
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,19 +64,15 @@ export function buildLayoutClient( | |
| addTypeGuardStatements(sourceFile, { | ||
| envVarName: envNames.server ?? defaultEnvNames.server, | ||
| }); | ||
| if (typeof envNames.auth === "object" && "apiKey" in envNames.auth) { | ||
| if (typeof envNames.auth === "object") { | ||
| addTypeGuardStatements(sourceFile, { | ||
| envVarName: envNames.auth.apiKey ?? defaultEnvNames.apiKey, | ||
| }); | ||
| } else if ( | ||
| typeof envNames.auth === "object" && | ||
| "username" in envNames.auth | ||
| ) { | ||
| addTypeGuardStatements(sourceFile, { | ||
| envVarName: envNames.auth?.username ?? defaultEnvNames.username, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Generated code requires all auth env vars unnecessarilyThe type guard generation now adds throw statements for |
||
| envVarName: envNames.auth.username ?? defaultEnvNames.username, | ||
| }); | ||
| addTypeGuardStatements(sourceFile, { | ||
| envVarName: envNames.auth?.password ?? defaultEnvNames.password, | ||
| envVarName: envNames.auth.password ?? defaultEnvNames.password, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
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.
Wrong adapter selected due to property existence check
The condition
"apiKey" in envNames.authchecks for property existence, not truthiness. With the changes intypegen.ts, theenvNames.authobject now always includesapiKeyas a property (even when set toundefinedfor username/password auth). Since"apiKey" in { apiKey: undefined, username: "X" }returnstrue, the OttoAdapter branch is incorrectly selected for username/password authentication. The generated code would referenceprocess.env.undefined, completely breaking username/password auth. The check needs to verify the value is truthy (e.g.,envNames.auth.apiKey) rather than just checking property existence.Additional Locations (1)
packages/typegen/src/buildLayoutClient.ts#L134-L135