Split `src/core/auth/enhanced-auth.service.ts` (570 lines) by authentication concern
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- nodejs, typescript
- Domain
- authentication, backend
Research direction
Start with src/core/auth/enhanced-auth.service.ts and src/core/auth/auth.service.ts, comparing how each issues tokens (generateTokens() and the expiresIn arguments) and where bcrypt is called. Read closed issue #8 before choosing which service becomes the main implementation. Done means token issuance lives in one place, no file in src/core/auth/ exceeds about 350 lines, and the e2e specs under test/ pass without changed assertions. Confirm those specs run first, because the issue says some are not run by npm test.
Written by the indexing model from the issue text.
Description
Problem
src/core/auth/enhanced-auth.service.ts is 570 lines and handles at least four concerns:
- Login/registration (
bcryptat lines 88, 166, 462, 526) - Token generation (
generateTokens()at line 549) and refresh-token persistence - Two-factor flows (
twoFactorVerifiedthreaded through the token payload, line 562) - Delegation and email-linking (it imports
email.service.tsandemail-linking.service.ts)
It also overlaps with src/core/auth/auth.service.ts — both inject JwtService, both do bcrypt password work (auth.service.ts:137), and both mint access tokens. They disagree on expiry: auth.service.ts:99,151 passes expiresIn: "15m", while enhanced-auth.service.ts:564 passes nothing. That divergence is the subject of a separate issue, but it is a direct consequence of the overlap.
Why it matters
Authentication is the highest-stakes code in the repository, and it is spread across two overlapping services with inconsistent behaviour. Reviewing a security change means reviewing 570 lines to find out what actually changed. The overlap is also how the token-expiry divergence went unnoticed.
Suggested Direction
- Extract the token concern first — it is the most self-contained and the most security-relevant:
Both belong behind one implementation, sosrc/core/auth/services/token.service.ts // issue/refresh/verify, TTL constants src/core/auth/services/refresh-token.service.ts // persistence, rotation, revocationauth.service.tsandenhanced-auth.service.tscannot disagree about expiry again. - Extract two-factor into
two-factor.service.ts, covering thetwoFactorVerifiedclaim. - Resolve the service overlap — decide whether
enhanced-auth.service.tsis the intended implementation andauth.service.tsa thin wrapper, or the reverse. There is a closed issue (#8, "Aligncore/authModule — Token Blacklist Injection & Strategy Pattern Consolidation") that may already have established a direction; read it before proposing a new one.
Constraints
- Do not change token semantics in this refactor. Fixing the missing expiry is a separate, deliberate change (see the dedicated issue) — mixing it into a refactor makes both harder to review and harder to roll back.
- Existing auth e2e specs must pass:
test/wallet-auth.spec.ts,test/enhanced-auth.service.spec.ts,test/recovery.spec.ts,test/auth/wallet-advanced.e2e-spec.ts,test/traditional-auth.e2e-spec.ts. Note that five of these live undertest/and are not currently executed bynpm test— see the unreachable-specs issue; fix that first or verify againstnpm run test:e2e. - Keep session behaviour (the
ipAddress/userAgentrecorded on refresh tokens) unchanged.
Acceptance Criteria
- No file in
src/core/auth/exceeds ~350 lines. - Token issuance exists in exactly one place; both auth services call it.
- Refresh-token persistence is fully encapsulated in its own service.
- All auth e2e suites pass with unchanged assertions.
- No token behaviour change is bundled into this PR.
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 55
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 5
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SourceXXL/alian_structure-api
-
good first issue help wanted security
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#266 ·
-
Parallelize the cache-warming loop in `cache-warming.service.ts` — warmers run strictly sequentiallyPossibly taken @syntaxsuuvam-spec claimed this 5 days ago. Opengood first issue performance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#240 ·
-
documentation help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SourceXXL/alian_structure-api#215 ·
-
good first issue refactor tooling
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
SourceXXL/alian_structure-api#199 ·
-
help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
SourceXXL/alian_structure-api#196 ·
All issues in SourceXXL/alian_structure-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
melgarafael/DeskcommCRM#3000 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
callstackincubator/simlock#639 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
aws/agentcore-cli#2606 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 7 days
-
ai-driven-qa bug Cosmetic
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day