refactor: introduce AuthClient abstraction (Phase 1 of #64) - #65
Open
xiaomi7732 wants to merge 2 commits into
Open
refactor: introduce AuthClient abstraction (Phase 1 of #64)#65xiaomi7732 wants to merge 2 commits into
xiaomi7732 wants to merge 2 commits into
Conversation
Refactor MSAL auth behind an AuthClient interface so future providers (e.g. Google Identity Services) can plug in without touching consumers. Strict refactor — zero behavior change. Microsoft remains the only provider. Architecture: - lib/auth/types.ts: AuthClient interface (acquireToken with silentOnly option, login, logout, getUser, isAuthenticated, busy) - lib/auth/microsoft/MicrosoftAuthClient.ts: wraps MSAL (loginPopup, acquireTokenSilent+Popup, logoutPopup, accounts[0]) - lib/auth/useAuthClient.ts: hook returning the active client (today always Microsoft) Implementation notes: - acquireToken reads accounts fresh from instance.getAllAccounts() rather than from useMsal-captured state, eliminating the post-loginPopup race identified in PR #63. The one-shot store hack in app/page.tsx is no longer needed. - getUser sources displayName and email from MSAL account info instead of calling Graph /me. Removes a wasted round-trip on the books page. Removed: - lib/hooks/useGraphToken.ts (logic absorbed into MicrosoftAuthClient) - getUserInfo + UserInfo type from graphService.ts (no longer used) Other: - All pages and useBookId now use useAuthClient instead of useGraphToken. - HamburgerMenu signout uses auth.logout() instead of instance.logoutPopup directly. - app/page.tsx silent background check uses acquireToken({ silentOnly: true }) instead of constructing a one-shot MultiBackendStore. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Introduces an AuthClient abstraction around the existing MSAL authentication flow as Phase 1 of #64, keeping Microsoft as the only provider while preparing consumers for future auth providers.
Changes:
- Adds
AuthClienttypes and a Microsoft MSAL-backed implementation. - Replaces
useGraphTokenusage across pages, hooks, store creation, and menu logout. - Removes direct Graph
/meuser info access and deleted the old token hook.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/arrange-v4/lib/auth/types.ts |
Defines the new auth abstraction contract. |
src/arrange-v4/lib/auth/useAuthClient.ts |
Exposes the active auth client hook. |
src/arrange-v4/lib/auth/microsoft/MicrosoftAuthClient.ts |
Implements AuthClient using MSAL. |
src/arrange-v4/lib/hooks/useGraphToken.ts |
Removes the old MSAL token hook. |
src/arrange-v4/lib/store/useStore.ts |
Injects token acquisition through AuthClient. |
src/arrange-v4/lib/hooks/useBookId.ts |
Uses auth abstraction for authentication state. |
src/arrange-v4/lib/graphService.ts |
Removes user-info Graph helper. |
src/arrange-v4/components/HamburgerMenu.tsx |
Routes sign-out through AuthClient. |
src/arrange-v4/app/page.tsx |
Uses AuthClient for login and silent availability checks. |
src/arrange-v4/app/books/page.tsx |
Uses AuthClient for login/logout and user display. |
src/arrange-v4/app/matrix/page.tsx |
Uses AuthClient in matrix page auth flow. |
src/arrange-v4/app/scrum/page.tsx |
Uses AuthClient in scrum page auth flow. |
src/arrange-v4/app/cancelled/page.tsx |
Uses AuthClient in cancelled page auth flow. |
The previous getUser() captured useMsal's accounts at hook render time, so a caller doing await auth.login(); auth.getUser() would get stale pre-login state for one render cycle. Read from instance.getAllAccounts() fresh — same fix as acquireToken. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
Author
PR Review Loop Summary
|
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.
Summary
Phase 1 of #64 — refactor MSAL auth behind an
AuthClientinterface so future providers (e.g. Google Identity Services for the Sheets backend) can plug in without touching consumers.Strict refactor. Zero behavior change. Microsoft remains the only provider. This is the matching auth-side companion to the storage abstraction in #63.
Architecture
Interface
Implementation notes
acquireTokenreads accounts fresh frominstance.getAllAccounts()rather than from useMsal-captured state. This eliminates the post-loginPopup race that PR refactor: introduce storage abstraction layer behind TodoStore #63 worked around with a one-shot store. The hack is gone —app/page.tsxnow callsstore.listBooks()directly afterauth.login().acquireToken({ silentOnly: true })for background checks. Replaces theinstance.acquireTokenSilentdirect call inapp/page.tsx's availability check. Never opens a popup from a useEffect.getUser()sources displayName/email from MSAL account info instead of calling/meon Graph. Books page no longer makes a round-trip just to render the welcome banner.Removed
lib/hooks/useGraphToken.ts— logic absorbed intoMicrosoftAuthClient.getUserInfo+UserInfofromgraphService.ts— no longer used.Changed consumers
All pages and hooks that previously imported
useGraphTokennow useuseAuthClient:app/page.tsx(usessilentOnlyfor background check)app/books/page.tsx(usesauth.getUser()andauth.logout())app/matrix/page.tsx,app/scrum/page.tsx,app/cancelled/page.tsxlib/hooks/useBookId.ts,lib/store/useStore.tscomponents/HamburgerMenu.tsx(usesauth.logout()instead ofinstance.logoutPopup)Build + lint
npm run build✅npm run lintshows no new errors/warnings (pre-existing ones unchanged)Out of scope
Smoke test checklist (manual)
?bookId=...URLs still resolve