Repository navigation
fix(oauth): prevent duplicate connections on re-authentication #5
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,16 @@ export async function createProviderConnection(data) { | |||||||||||||
| "SELECT * FROM provider_connections WHERE provider = ? AND auth_type = 'oauth' AND email = ?" | ||||||||||||||
| ) | ||||||||||||||
| .get(data.provider, data.email); | ||||||||||||||
| } else if (data.authType === "oauth" && !data.email) { | ||||||||||||||
| // Fallback for providers that don't return email (e.g. Codex): | ||||||||||||||
| // find the most recent failed connection for this provider to update instead of duplicating | ||||||||||||||
| existing = db | ||||||||||||||
| .prepare( | ||||||||||||||
| `SELECT * FROM provider_connections WHERE provider = ? AND auth_type = 'oauth' | ||||||||||||||
| AND (test_status = 'auth_failed' OR test_status = 'refresh_failed' OR test_status = 'error') | ||||||||||||||
| ORDER BY updated_at DESC LIMIT 1` | ||||||||||||||
|
Comment on lines
+58
to
+60
Contributor
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. For better readability and conciseness, you can use the
Suggested change
|
||||||||||||||
| ) | ||||||||||||||
| .get(data.provider); | ||||||||||||||
|
Comment on lines
+53
to
+62
|
||||||||||||||
| } else if (data.authType === "apikey" && data.name) { | ||||||||||||||
| existing = db | ||||||||||||||
| .prepare( | ||||||||||||||
|
|
||||||||||||||
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 fallback upsert is filtering on
test_status = 'auth_failed' | 'refresh_failed', but in this codebaseauth_failed/refresh_failedare stored inerror_code(whiletest_statusis typicallyactive/error/etc.). As written, this will almost never match the intended rows. Update the WHERE clause to filter onerror_code(and/orlast_error_type) instead oftest_statusfor these values.