fix(auth): auto-authenticate on browser reopen using silent fallback chain#293
Merged
fix(auth): auto-authenticate on browser reopen using silent fallback chain#293
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the frontend’s Azure AD authentication flow so returning users are automatically re-authenticated on browser reopen, reducing unnecessary /login prompts while still handling first-time visitors.
Changes:
- Extend
loginSilently()to tryacquireTokenSilent()and then fall back tossoSilent(); introduce tenant-aware account selection andhasCachedAccounts(). - Update
App.tsxto auto-triggerloginWithRedirect()when silent auth fails but tenant-matching accounts exist. - Update
LoginView.tsxto auto-redirect when arriving at/loginwith cached tenant accounts.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| frontend/src/utils/msal.ts | Adds tenant-aware account selection, cached-account detection, and a silent auth fallback chain. |
| frontend/src/App.tsx | Uses cached-account detection to decide between auto-redirect vs. navigating to /login. |
| frontend/src/views/Authorization/LoginView.tsx | Adds an automatic redirect safety net for direct /login visits when accounts are cached. |
Comments suppressed due to low confidence (1)
frontend/src/App.tsx:93
loginWithRedirect()is awaited here without error handling. If the redirect initiation fails,componentDidMountwill throw and can break initial app render rather than falling back to/login. Wrap the redirect attempt in try/catch and fall back tonavigate(NavigationPaths.Login)(or show an error) on failure.
if (await hasCachedAccounts()) {
await loginWithRedirect()
} else if (this.props.pathname !== NavigationPaths.Login && this.props.pathname !== NavigationPaths.Privacy) {
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the browser reopen flow where users had to click Sign in even though Azure would accept the redirect immediately with no credential prompt.