-
Notifications
You must be signed in to change notification settings - Fork 0
feat: thread authenticated user id through chat, feedback, and ADK #51
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
Draft
nonumpa
wants to merge
3
commits into
master
Choose a base branch
from
feature/issue-47-user-id
base: master
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.
+110
−24
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,23 @@ | ||
| import { useAuth } from '@/lib/auth' | ||
|
|
||
| interface LoginPromptProps { | ||
| message?: string | ||
| } | ||
|
|
||
| export function LoginPrompt({ | ||
| message = '登入後即可開始與 Cofacts.ai 對話', | ||
| }: LoginPromptProps) { | ||
| const { login } = useAuth() | ||
| return ( | ||
| <div className="border-t border-border-subtle bg-white p-4 flex flex-col items-center gap-3"> | ||
| <p className="text-sm text-text-muted text-center">{message}</p> | ||
| <button | ||
| type="button" | ||
| onClick={() => login()} | ||
| className="px-4 py-1.5 rounded-full bg-primary text-white text-sm font-medium hover:bg-primary/90 cursor-pointer focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2" | ||
| > | ||
| 登入 / 註冊 | ||
| </button> | ||
| </div> | ||
| ) | ||
| } |
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
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,23 @@ | ||
| // Server-side helper that resolves the current user's Cofacts ID for use as | ||
| // the ADK `user_id` path/body parameter. Reads the HttpOnly cofacts_session | ||
| // cookie (via cofactsExec) and dispatches GetCurrentUser. Throws a 401-shaped | ||
| // Response when no authenticated user is present so callers can let the | ||
| // framework propagate it back to the browser. | ||
|
|
||
| import { getCurrentUserServerFn } from './me.functions' | ||
|
|
||
| export class UnauthorizedError extends Error { | ||
| readonly status = 401 | ||
| constructor(message = 'Authentication required') { | ||
| super(message) | ||
| this.name = 'UnauthorizedError' | ||
| } | ||
| } | ||
|
|
||
| export async function resolveAdkUserIdOrThrow(): Promise<string> { | ||
| const user = await getCurrentUserServerFn() | ||
| if (!user) { | ||
| throw new UnauthorizedError() | ||
| } | ||
| return user.id | ||
| } | ||
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.
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 comment states that this helper throws a "401-shaped Response", but the implementation on lines 19-21 throws a custom
UnauthorizedErrorobject.In TanStack Start, throwing a standard
Errorin acreateServerFn(like those inchatSessions.functions.ts) typically results in a 500 Internal Server Error on the client side. To allow the framework to propagate a specific HTTP status code (like 401) automatically to the browser, you should throw aResponseobject instead.If you prefer using the custom error class for manual handling (as seen in
run-sse.ts), please update the comment to reflect that anErroris thrown rather than aResponse.