refactor: inject localStorage via Angular DI in JwtService#20
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
refactor: inject localStorage via Angular DI in JwtService#20devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
- Create LOCAL_STORAGE InjectionToken backed by localStorage - Refactor JwtService to inject Storage via the token instead of accessing window.localStorage directly - Use proper Storage API (getItem/setItem/removeItem) instead of bracket notation - Rewrite tests to provide a mock Storage through TestBed DI rather than monkey-patching window.localStorage - Add zone.js dev dependency (required by test setup but was missing) Co-Authored-By: Wes Convery <2wconvery@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Reverts an accidental version mismatch where @angular/core was at 21.2.4 while all other @angular/* packages remained at 21.1.1. Co-Authored-By: Wes Convery <2wconvery@gmail.com>
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
Refactors
JwtServiceto receivelocalStoragethrough Angular's dependency injection system instead of accessingwindow.localStoragedirectly. This makes the service testable without monkey-patchingwindow.Changes:
LOCAL_STORAGEInjectionToken (storage.token.ts):providedIn: 'root'with a factory that returnslocalStorage. No changes needed inapp.config.ts.JwtServicenowinject(LOCAL_STORAGE)and uses properStorageAPI methods (getItem/setItem/removeItem) instead of bracket notation.jwt.service.spec.tsrewritten to provide aMap-backed mockStoragevia{ provide: LOCAL_STORAGE, useValue: mockStorage }— no moreObject.defineProperty(window, 'localStorage', ...).zone.jsdev dependency — was already imported in test setup but missing frompackage.json, causing all test suites to fail.@angular/coreback to 21.1.1 to match all other@angular/*packages (was accidentally bumped to 21.2.4 by a previous dependabot PR).Review & Testing Checklist for Human
getToken()now returns''(empty string) instead ofundefinedwhen no token is stored — all existing callers use truthiness checks so this is backward-compatible, but worth confirming no downstream code relies onundefinedspecificallybun run testto confirm all 179 tests passNotes
user.service.spec.tsalready mockedJwtServiceentirely via{ provide: JwtService, useValue: ... }, so it required no changes.Link to Devin session: https://app.devin.ai/sessions/6c4b7428c4f54351919bb91211361338
Requested by: @WesternConcrete
Devin Review