-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate Auth to Result-based error handling; add shared Result/error infra #71
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
15 changes: 12 additions & 3 deletions
15
apps/admin-frontend/src/features/auth/application/test-helpers/createFakeAuthRepository.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| import type { AuthRepository } from '@/features/auth/application/repositories/AuthRepository' | ||
| import { AuthFlowError } from '@/features/auth/application/errors/AuthFlowError' | ||
| import { failure, success } from '@/shared/application/Result' | ||
|
|
||
| const NOT_IMPLEMENTED = new AuthFlowError({ | ||
| code: 'unexpected', | ||
| flowCode: 'AUTH_LOGIN_FAILED', | ||
| message: 'not implemented in this fake', | ||
| retryable: false, | ||
| }) | ||
|
|
||
| export function createFakeAuthRepository(overrides: Partial<AuthRepository> = {}): AuthRepository { | ||
| return { | ||
| initiateLogin: () => Promise.resolve(), | ||
| handleCallback: () => Promise.reject(new Error('not implemented in this fake')), | ||
| initiateLogin: () => Promise.resolve(success(undefined)), | ||
| handleCallback: () => Promise.resolve(failure(NOT_IMPLEMENTED)), | ||
| getCurrentSession: () => Promise.resolve(null), | ||
| logout: () => Promise.resolve(), | ||
| logout: () => Promise.resolve(success(undefined)), | ||
| ...overrides, | ||
| } | ||
| } |
4 changes: 1 addition & 3 deletions
4
apps/admin-frontend/src/features/auth/application/use-cases/GetCurrentSession.test.ts
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
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
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
3 changes: 2 additions & 1 deletion
3
apps/admin-frontend/src/features/auth/application/use-cases/InitiateLogin.test.ts
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
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
3 changes: 2 additions & 1 deletion
3
apps/admin-frontend/src/features/auth/application/use-cases/Logout.test.ts
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Keep the established frontend error contract.
This migration introduces a second error-handling model in
apps/admin-frontend. Existing frontend flows use typed thrown errors and presentation-layer error mapping. The Result contract also requires temporary Catalog compatibility adapters, which confirms the contract split.apps/admin-frontend/src/features/auth/application/use-cases/HandleAuthCallback.ts#L31-L50: restore the throw-and-catch callback contract with typedAuthFlowErrorfailures.apps/admin-frontend/src/features/auth/application/use-cases/Logout.ts#L12-L13: restore thePromise<void>use-case contract and propagate typed failures through exceptions.apps/admin-frontend/src/features/auth/presentation/AuthContext.ts#L15-L17: expose the existing action contracts instead of Result unions.apps/admin-frontend/src/features/auth/presentation/CallbackPage/CallbackPage.tsx#L17-L21: restore error catching andtoAuthFlowFeedbackmapping.apps/admin-frontend/src/features/auth/application/test-helpers/createFakeAuthRepository.ts#L14-L17: update fake defaults to match the restored repository contract.Based on learnings,
apps/admin-frontendmust use the established throw-and-catch convention for domain and HTTP failures and must not apply the backend-only Result policy to frontend code.📍 Affects 5 files
apps/admin-frontend/src/features/auth/application/use-cases/HandleAuthCallback.ts#L31-L50(this comment)apps/admin-frontend/src/features/auth/application/use-cases/Logout.ts#L12-L13apps/admin-frontend/src/features/auth/presentation/AuthContext.ts#L15-L17apps/admin-frontend/src/features/auth/presentation/CallbackPage/CallbackPage.tsx#L17-L21apps/admin-frontend/src/features/auth/application/test-helpers/createFakeAuthRepository.ts#L14-L17🤖 Prompt for AI Agents
Source: Learnings