[BUG]: Refactor `LoginView` to fix force-unwrap crash, migrate to async/await, and display error messages
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 0
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
### Description:
The `LoginView` in `CForgeApp.swift` has multiple serious issues: a force-unwrap that can crash the app, legacy callback-based networking (`URLSession.dataTask`), and error messages that are set but **never displayed** to the user.
### Current Behavior:
**1. Force-Unwrap Crash (Line 159):**
```swift
URLSession.shared.dataTask(with: URL(string: apiUrl)!) { ... }
```
If a user enters a handle with special characters (spaces, unicode), `URL(string:)` returns `nil` and the app crashes.
**2. Legacy Networking:**
The login uses `URLSession.shared.dataTask` with `DispatchQueue.main.async` callbacks — the only screen in the app still using this pattern. The Problem feature already uses `async/await`.
**3. Silent Errors:**
`errorMessage` is set on failure, but the `LoginView` body has **no UI element** that displays `errorMessage`. Errors are invisible to the user — the loading spinner just disappears with no feedback.
**4. No Input Sanitization:**
- Leading/trailing whitespace is not trimmed from the handle.
- The handle is not validated against Codeforces' handle format (alphanumeric + underscores, 3-24 chars).
**5. Architecture Smell:**
`LoginView`, `UserManager`, `NeonTextFieldStyle`, and `NeonButtonStyle` are all defined inside `CForgeApp.swift` (a 240-line file). These should be extracted into their own files.
### Feature Requirements:
- Fix the force-unwrap by safely constructing the URL and handling `nil`.
- Migrate `verifyHandle()` to `async/await` using `URLSession.shared.data(from:)`.
- Add visible error state UI — display `errorMessage` in a styled text view or alert below the text field.
- Add input sanitization: trim whitespace, validate handle format before making the API call.
- Extract `LoginView` into its own file (`CForge/Views/Auth/LoginView.swift`).
- Extract `NeonTextFieldStyle` and `NeonButtonStyle` into `CForge/Views/Common/` or `Theme.swift`.
- Use the existing `NetworkError` enum for structured error handling.
### Key Files:
| Action | File |
|--------|------|
| **MODIFY** | `CForge/CForgeApp.swift` (remove LoginView, keep only App struct + UserManager) |
| **CREATE** | `CForge/Views/Auth/LoginView.swift` |
| **MODIFY** | `CForge/Theme.swift` or **CREATE** `CForge/Views/Common/NeonStyles.swift` (move button/text styles) |
### Expected Outcome:
- No force-unwrap crash on malformed input.
- Login uses `async/await`, consistent with the rest of the codebase.
- Error messages are visually displayed to the user with proper theming.
- Input is trimmed and validated before making an API call.
- `CForgeApp.swift` is clean — only the `App` struct and `UserManager`, nothing else.
Contributor 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.
Research direction
Start with CForge/CForgeApp.swift and inspect LoginView.verifyHandle(), the existing NetworkError enum, and the Problem feature's async/await usage. Review the listed destination files before moving LoginView and the neon styles. Done means malformed handles no longer crash, validation and visible errors work, login uses async/await, and CForgeApp.swift retains only the App struct and UserManager.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100