-
Notifications
You must be signed in to change notification settings - Fork 31
Documents support in chat #231
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
Open
dhirenmathur
wants to merge
5
commits into
main
Choose a base branch
from
doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
772e4cb
Documents support in chat
dhirenmathur 8e7279c
Update UX for doc support feature
dhirenmathur afa0ea9
Merge remote-tracking branch 'origin/main' into doc
dhirenmathur 96fc368
merge master
dhirenmathur 48a6053
doc attachment fixes
dhirenmathur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| GithubAuthProvider, | ||
| linkWithPopup, | ||
| reauthenticateWithPopup, | ||
| User, | ||
| UserCredential, | ||
| } from "firebase/auth"; | ||
|
|
||
| type GithubOAuthResult = | ||
| | { | ||
| status: "linked"; | ||
| credential: UserCredential; | ||
| accessToken: string | null; | ||
| providerUsername?: string; | ||
| } | ||
| | { | ||
| status: "already_linked"; | ||
| }; | ||
|
|
||
| const GITHUB_PROVIDER_ID = "github.com"; | ||
|
|
||
| /** | ||
| * Triggers GitHub OAuth for the given Firebase user ensuring the required scopes | ||
| * are granted. If the account is already linked, it skips the popup. | ||
| */ | ||
| export const ensureGithubOAuth = async ( | ||
| user: User | null, | ||
| options: { forceReauth?: boolean } = {} | ||
| ): Promise<GithubOAuthResult> => { | ||
| if (!user) { | ||
| throw new Error("GitHub OAuth requires an authenticated user."); | ||
| } | ||
|
|
||
| const hasGithubLinked = user.providerData?.some( | ||
| (provider) => provider.providerId === GITHUB_PROVIDER_ID | ||
| ); | ||
|
|
||
| const provider = new GithubAuthProvider(); | ||
| provider.addScope("read:user"); | ||
| provider.addScope("read:org"); | ||
| provider.addScope("user:email"); | ||
|
|
||
| // When the account is already linked we optionally re-authenticate to refresh tokens. | ||
| if (hasGithubLinked && !options.forceReauth) { | ||
| return { status: "already_linked" }; | ||
| } | ||
|
|
||
| try { | ||
| const result = hasGithubLinked | ||
| ? await reauthenticateWithPopup(user, provider) | ||
| : await linkWithPopup(user, provider); | ||
|
|
||
| const credential = GithubAuthProvider.credentialFromResult(result); | ||
| const accessToken = | ||
| credential?.accessToken ?? | ||
| (result as any)?._tokenResponse?.oauthAccessToken ?? | ||
| null; | ||
|
|
||
| const providerUsername = (result as any)?._tokenResponse?.screenName; | ||
|
|
||
| return { | ||
| status: "linked", | ||
| credential: result, | ||
| accessToken, | ||
| providerUsername, | ||
| }; | ||
| } catch (error: any) { | ||
| // If the provider is already linked but reauth is not requested, surface as already linked. | ||
| if (error?.code === "auth/provider-already-linked") { | ||
| return { status: "already_linked" }; | ||
| } | ||
| throw error; | ||
| } | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
Accessing undocumented Firebase internal APIs.
Lines 58 and 61 access internal Firebase response fields via
(result as any)?._tokenResponse, which are not part of the documented Firebase API. These fields could change or be removed in future Firebase SDK updates, potentially breaking this functionality.Consider these alternatives:
credential?.accessToken(line 57) and remove the fallback to_tokenResponse.oauthAccessTokenscreenName, consider fetching the GitHub username via the GitHub API using the access token instead of relying on internal Firebase fieldsIf the undocumented fields are required, add a TODO comment and error handling:
const accessToken = credential?.accessToken ?? + // TODO: Remove fallback to internal API when Firebase SDK provides documented alternative (result as any)?._tokenResponse?.oauthAccessToken ?? null; - const providerUsername = (result as any)?._tokenResponse?.screenName; + // TODO: Fetch username via GitHub API instead of internal Firebase field + const providerUsername = (result as any)?._tokenResponse?.screenName ?? null;I'll verify this review comment by inspecting the actual code and researching Firebase SDK documentation.
🏁 Script executed:
Length of output: 1025
🏁 Script executed:
Length of output: 72
🏁 Script executed:
Length of output: 715
🏁 Script executed:
Length of output: 2050
🌐 Web query:
💡 Result:
Short answer: _tokenResponse is an internal SDK implementation detail — it is not part of the documented, supported public API. The official docs show GithubAuthProvider.credentialFromResult(userCredential) returns an OAuthCredential (with .accessToken) and do not document or promise any _tokenResponse property. [1][2]
References:
Sources:
🌐 Web query:
💡 Result:
Short answer: Firebase's GitHub provider does NOT return the GitHub "username"/"login" (screen name) in user.providerData. It returns displayName, email, photoURL and a numeric GitHub uid. To get the GitHub login you must obtain the provider OAuth access token from the sign-in result and call the GitHub API (GET https://api.github.com/user) to read the "login" field.
How (brief):
Sources: Firebase docs on GitHub sign-in and credentials / providerData and a community explanation. [1] [2] [3]
References
[1] Firebase — GitHub sign-in docs (access token / credential examples).
[2] Firebase JS API reference (GithubAuthProvider / OAuthCredential examples).
[3] StackOverflow — explanation that providerData lacks GitHub username and you must call GitHub API to resolve it.
Remove reliance on undocumented Firebase internal APIs
_tokenResponse.The
_tokenResponseobject is an internal SDK implementation detail, not part of the documented public API. Line 58 (fallback to_tokenResponse?.oauthAccessToken) and line 61 (_tokenResponse?.screenName) create maintenance risk and should be replaced with documented alternatives:credential?.accessTokenfromOAuthCredentialis the supported public API; remove the fallback to_tokenResponse.oauthAccessToken.screenName) in documented fields. Fetch the GitHub login via the GitHub API using the access token (GET https://api.github.com/user), or removeproviderUsernameif not required.Replace with:
📝 Committable suggestion
🤖 Prompt for AI Agents
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.
does oauth changes required for documents support?
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 949
🏁 Script executed:
Length of output: 6183
@yashkrishanNo, the OAuth changes are not required for document support.Based on my search of the codebase:
ensureGithubOAuthutility is not used anywhere - there are no imports or usages of this function in the codebaseChatService(validateDocument, uploadAttachment, etc.)link-githubandonboardingpages still use Firebase'slinkWithPopupdirectlyIt appears that the OAuth refactoring (
github-oauth.tscreation and related page updates) was bundled into this PR alongside the document support feature, but they are separate, unrelated changes. The document support functionality works entirely through the file upload and attachment APIs and doesn't require any GitHub OAuth integration.