Refactor auth signup with role assignment, account self-service APIs, and simplified DataSeeder#2
Merged
Conversation
- Add optional `role` field to SignUpRequest (only ROLE_USER allowed at signup for security) - Update AuthController to assign ROLE_USER during signup with RoleRepository - Create CreateAccountDTO with accountName and currency (ISO 4217 pattern validation) - Add findAllByUser to AccountRepository - Add POST /api/account/create and GET /api/account/list to AccountController (both rate-limited) - Simplify DataSeeder: keep only roles, systemAdmin (system@admin.com), and CENTRAL_BANK - Add DataIntegrityViolationException handling for concurrent seeder initialization Co-authored-by: mayank1008-tech <245725096+mayank1008-tech@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor authentication flow and data seeding for user roles
Refactor auth signup with role assignment, account self-service APIs, and simplified DataSeeder
Mar 15, 2026
mayank1008-tech
approved these changes
Mar 15, 2026
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.
Pre-seeded test users (alice/bob/charlie) with hardcoded balances made the onboarding flow non-production-ready. No API existed for users to create their own accounts post-signup, and role assignment was absent from the registration flow.
Auth: Role assignment on signup
/api/auth/signupnow assignsROLE_USERviaRoleRepository. TheSignUpRequestaccepts an optionalrolefield for extensibility, but role is always forced toROLE_USERserver-side — prevents self-escalation toROLE_ADMIN.New account self-service endpoints (
AccountController)POST /api/account/create— creates a zero-balance account for the authenticated user; rate-limitedGET /api/account/list— returns all accounts owned by the authenticated user; rate-limitedcurrencyvalidated against ISO 4217 pattern (^[A-Z]{3}$).Simplified DataSeeder
Removed alice/bob/charlie test users and their pre-seeded balances. Seeder now initializes only:
ROLE_USERandROLE_ADMINrolessystemAdminuser (system@admin.com)CENTRAL_BANKaccount (0 balance)Wrapped in
DataIntegrityViolationExceptioncatch to handle concurrent startup races.Supporting changes
AccountRepository: addedfindAllByUser(User user)CreateAccountDTO: new payload withaccountName+currencyOriginal prompt
Objective
Refactor the authentication flow and data seeding to support:
Changes Required
1. Update SignUpRequest
rolefield (Set)2. Update AuthController
/api/auth/signupto assign roles during user registration3. Update AccountController
POST /api/account/createendpoint to create new accountsGET /api/account/listendpoint to list user accounts4. Create CreateAccountDTO
5. Simplify DataSeeder
Benefits
The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: Let me check your actual project to see what's going on:
Assistant: The repo is showing as inaccessible. Let me ask you directly - I need to see a few things to debug this:
📋 Can you send me these 3 files?
Your current
Account.javamodel - Show me the full class including@Versionfield (if you have optimistic locking)Your current
LedgerEntry.javamodel - Show me all the relationshipsYour current
DataSeeder.java- What you currently have🔍 My Suspicion
I think the issue might be one of these:
Issue 1: Optimistic Locking
Issue 2: Account not saving
Issue 3: Detached entity
The account object might be detached after the first save.
Please share those 3 files so I can see exactly what's happening! 🔎
User: here you go
Assistant: Found it! 🎯 The issue is the
@Versionfield in Account causing optimistic locking conflicts!When you update the same account multiple times in the seeder, the version gets out of sync and the save fails silently.
Here's the fix: