-
-
Notifications
You must be signed in to change notification settings - Fork 260
Give bit Boilerplate AI Chatbot fresh access to the user auth state (#11955) #11956
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
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThe changes integrate sign-in functionality into the AI chatbot by adding authentication awareness, enabling the chatbot to prompt users to sign in via a modal, pass user context through the chat pipeline, and personalize greetings with the user's display name across multiple languages. Changes
Sequence DiagramsequenceDiagram
participant Client
participant AppClientCoordinator
participant SignInModalService
participant HubConnection
participant AppChatbot
participant AppHub
participant AppDbContext
rect rgb(200, 220, 240)
Note over Client,AppDbContext: Sign-In Flow Initiated by Chatbot
AppChatbot->>AppChatbot: ShowSignInModal() invoked by AI
AppChatbot->>HubConnection: Invoke SHOW_SIGN_IN_MODAL via SignalR
HubConnection->>AppClientCoordinator: Receive SHOW_SIGN_IN_MODAL signal
AppClientCoordinator->>SignInModalService: Call SignIn()
SignInModalService->>Client: Display sign-in modal
Client->>SignInModalService: User credentials submitted
SignInModalService->>AppClientCoordinator: Return access token
AppClientCoordinator->>HubConnection: Send token back
HubConnection->>AppChatbot: Return UserDto
end
rect rgb(220, 240, 200)
Note over AppChatbot,AppDbContext: Authenticated Chat Message Processing
Client->>AppHub: Send chat message
AppHub->>AppHub: Extract user from HttpContext
AppHub->>AppChatbot: ProcessNewMessage(message, user)
AppChatbot->>AppChatbot: Generate per-message auth-aware variables
AppChatbot->>AppDbContext: Query user data for personalization
AppChatbot->>Client: Return AI response with user context
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Actionable comments posted: 3
♻️ Duplicate comments (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.sv.resx (1)
1142-1144: Dynamic greeting placeholder in Swedish resource looks consistentThe
{0}placeholder after “Hej” matches the base resource pattern and should work fine as long as call sites are updated as discussed for the main AppStrings.resx entry.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fa.resx (1)
1139-1144: Persian AI chat greeting localized correctly with{0}placeholderThe updated Persian AiChatPanelInitialResponse follows the same
{0}pattern as the base resource, enabling a personalized greeting while falling back cleanly when the argument is empty, assuming call sites are updated as already discussed.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.nl.resx (1)
1139-1144: Dutch AI chat greeting updated for dynamic user insertionThe Dutch AiChatPanelInitialResponse now accepts
{0}after “Hallo”, matching the base pattern and enabling personalized greetings once call sites pass the appropriate argument.
🧹 Nitpick comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs (1)
297-302: Consider handling sign-in cancellation and errors.The handler awaits
SignIn()but doesn't handle the case where the user cancels the sign-in modal or an error occurs. IfSignIn()fails or is cancelled,GetItem("access_token")may return a stale or null token.Additionally, consider wrapping the sign-in call in
InvokeAsyncfor consistency with other UI-affecting handlers in this file (e.g., lines 249-253, 259-263).🔎 Proposed improvement
hubConnection.Remove(SharedAppMessages.SHOW_SIGN_IN_MODAL); signalROnDisposables.Add(hubConnection.On(SharedAppMessages.SHOW_SIGN_IN_MODAL, async () => { - await signInModalService.SignIn(); - return await StorageService.GetItem("access_token"); + return await InvokeAsync(async () => + { + var success = await signInModalService.SignIn(); + return success ? await StorageService.GetItem("access_token") : null; + }); }));Verify that
SignInModalService.SignIn()returns a value indicating success/cancellation, or check the server-side handling inAppChatbot.ShowSignInModalfor null/empty token scenarios.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (17)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppAiChatPanel.razor.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Data/Configurations/Chatbot/SystemPromptConfiguration.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.ar.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.de.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.es.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fa.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fr.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.hi.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.nl.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.sv.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.zh.resxsrc/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/SharedAppMessages.cs
🧰 Additional context used
🧬 Code graph analysis (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/SharedAppMessages.cs (1)
SharedAppMessages(9-127)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/Contracts/IAuthTokenProvider.cs (2)
ClaimsPrincipal(9-9)ClaimsPrincipal(14-29)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cs (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Extensions/ClaimsPrincipalExtensions.cs (2)
IsAuthenticated(5-8)GetEmail(20-23)src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/SharedAppMessages.cs (1)
SharedAppMessages(9-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Agent
- GitHub Check: CodeQL analysis (csharp)
🔇 Additional comments (15)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Data/Configurations/Chatbot/SystemPromptConfiguration.cs (1)
71-123: Explicit “Requires sign-in” notes improve auth-aware guidanceAdding explicit “Requires sign-in.” bullets to Profile, Account, 2FA, Sessions, Dashboard, Categories, Products, Add/Edit Product, and Todo/Upgrade pages makes the auth requirements much clearer for the chatbot tools layer and aligns well with the PR objective.
Also applies to: 133-152
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs (1)
44-55: PassingHttpContext.UserintoProcessNewMessagealigns chatbot with current auth stateWiring
Context.GetHttpContext()!.Userthrough toProcessNewMessageis exactly what you need so the chatbot can react to per-message authentication changes (e.g., after a mid-session sign-in).The only assumption here is that
Context.GetHttpContext()is never null in your hosting setup; if you ever host this hub in a context where HttpContext might be absent (tests, non-HTTP transports), you may want a null-guard and fallback to an anonymous principal.src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.cs (1)
83-100: SyncingHttpContext.Userwith hub auth state is a solid improvementUpdating
Context.GetHttpContext()!.UserinsideChangeAuthenticationStateImplementationensures any scoped services (likeAppDbContext) that consultHttpContext.Usersee the current authentication state, which is important for the chatbot’s per-message behavior and for features keyed on the session.As with the chatbot file, this assumes
GetHttpContext()is never null for your hub connections. If there’s any chance of null (tests, alternate hosts), a defensive null-check with a fallback anonymous principal would avoid potentialNullReferenceExceptions.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.resx (1)
1139-1144: Format argument is properly handled in codeThe {0} placeholder in
AiChatPanelInitialResponseis correctly implemented. The only usage inAppAiChatPanel.razor.cs(line 143) properly passes a format argument via theLocalizercall, with conditional logic that passes an empty string for anonymous users or a space-prefixed display name for logged-in users. No runtime issues.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/SharedAppMessages.cs (1)
59-62: LGTM! New message constant properly defined.The
SHOW_SIGN_IN_MODALconstant is well-documented and follows the established pattern for server-to-client command messages. This enables the server to prompt the client to show the sign-in modal when needed, which aligns with the PR's objective of making the AI chatbot auth-aware.src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppAiChatPanel.razor.cs (3)
4-4: LGTM! Import added for user identity context.The import enables access to the
UserDtotype used in the cascading parameter.
16-17: LGTM! Cascading parameter enables auth-aware chatbot.The nullable
CurrentUserparameter properly handles both authenticated and anonymous user scenarios, enabling the chatbot to personalize greetings and be aware of the user's authentication state.
143-143: LGTM! Greeting personalization logic is correct.The implementation properly formats the greeting:
- When no user or empty DisplayName: passes empty string → "Greetings!"
- When user has DisplayName: passes " {name}" (with leading space) → "Greetings John!"
The ternary expression correctly handles null/empty cases, and the space is appropriately added in the C# code rather than the localized strings.
Note: The greeting is set when
SetDefaultValues()is called (on init and chat clear). If a user signs in during an active chat session, the greeting won't update until the chat is cleared. This is likely acceptable UX, but worth noting.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.es.resx (1)
1143-1143: LGTM! Localization updated to support dynamic greeting across all supported languages.The addition of the
{0}placeholder enables personalized greetings with the user's display name. The positioning is grammatically correct across all 10 localization files (English, Arabic, German, Spanish, Farsi, French, Hindi, Dutch, Swedish, and Chinese), and the format string will work properly with the calling code that passes either an empty string or a space-prefixed name.src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs (1)
27-29: LGTM on dependency injections.The
SignInModalServiceinjection follows the existing pattern and is appropriately placed within the SignalR-related dependencies block.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fr.resx (1)
1142-1144: Localization placeholder added correctly.The
{0}placeholder enables dynamic personalization with the user's display name. The pattern is consistent across all locale files in this PR.src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.ar.resx (1)
1142-1144: LGTM!The placeholder addition aligns with the coordinated localization effort across all supported languages.
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.de.resx (1)
1142-1144: LGTM!The German localization follows the same placeholder pattern for dynamic greeting personalization.
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cs (2)
72-79: Good separation of per-session vs per-message variables.The renaming to
variablesDefaultand the comment clarify the intent: these values are stable per SignalR connection. The per-messagevariablesPrompt(lines 114-122) correctly captures dynamic auth state.
95-100: LGTM on signature update.Adding
ClaimsPrincipal? userparameter enables per-message authentication awareness, aligning with the PR objective of making the chatbot aware of auth state changes.
...e/src/Server/Boilerplate.Server.Api/Data/Configurations/Chatbot/SystemPromptConfiguration.cs
Show resolved
Hide resolved
...emplates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cs
Show resolved
Hide resolved
...emplates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cs
Show resolved
Hide resolved
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.
Pull request overview
This PR enhances the AI chatbot in the bit Boilerplate template by providing it with fresh access to user authentication state. The changes enable the chatbot to check if a user is authenticated, prompt for sign-in when accessing protected features, and personalize greetings with the user's name.
Key Changes:
- Added authentication state awareness to the chatbot by passing the current user's ClaimsPrincipal to chat processing
- Implemented a new sign-in modal mechanism that can be triggered by the chatbot via SignalR
- Updated chatbot system prompts to include authentication requirements for various pages and features
- Personalized initial chatbot greeting to include the user's display name when available
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
SharedAppMessages.cs |
Added new SHOW_SIGN_IN_MODAL message constant for chatbot-triggered authentication |
AppStrings.*.resx (10 files) |
Updated AI chat panel greeting messages to include user name placeholder across all localizations |
AppHub.cs |
Updates HttpContext.User when authentication state changes to ensure fresh auth state |
AppHub.Chatbot.cs |
Passes current user ClaimsPrincipal to chatbot message processing |
AppChatbot.cs |
Adds ShowSignInModal tool, authentication state variables, user info to chat context, and related imports/dependencies |
SystemPromptConfiguration.cs |
Documents authentication requirements for protected pages and adds instructions for using the ShowSignInModal tool |
AppAiChatPanel.razor.cs |
Personalizes initial greeting message with current user's display name |
AppClientCoordinator.cs |
Handles SHOW_SIGN_IN_MODAL message from server and returns access token after sign-in |
...e/src/Server/Boilerplate.Server.Api/Data/Configurations/Chatbot/SystemPromptConfiguration.cs
Outdated
Show resolved
Hide resolved
...emplates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppChatbot.cs
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fr.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.es.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.hi.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.zh.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.sv.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.fa.resx
Show resolved
Hide resolved
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Resources/AppStrings.ar.resx
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Yas Moradi <yas@bitplatform.dev>
closes #11955
Summary by CodeRabbit
New Features
Localization
✏️ Tip: You can customize this high-level summary in your review settings.