Why I built it
I've been learning SwiftUI by building different projects, and one thing I noticed is that authentication screens involve much more than just placing a few TextFields and Buttons on screen.
You need validation, loading states, error handling, password rules, keyboard management, navigation between Sign In, Create Account and Forgot Password, and a structure that can eventually connect to a real backend.
I wanted to understand how all of these pieces could work together, so I built a complete reusable authentication flow called ModernLogin.
- Keeping validation separate
One of the things I learned was that putting every validation rule directly inside the views quickly makes the UI harder to maintain.
Instead, I centralized the validation logic so the views can focus mainly on displaying the interface and reacting to the result.
This also makes rules such as email validation, password requirements and matching passwords easier to reuse across different screens.
- Designing for different authentication states
Authentication isn't just an idle form and a success screen.
The UI also needs to represent states such as:
Loading
Success
Validation errors
Authentication errors
Building these states taught me to think about the complete user flow instead of only how the initial screen looks.
- Making the UI reusable
I didn't want the project to be tied to one app or one visual style.
I created AuthTheme and AuthConfig so parts of the authentication experience can be customized without rebuilding the entire interface.
I also added Light and Dark Mode support from the beginning instead of treating Dark Mode as something to add at the end.
- Keeping the backend separate
ModernLogin doesn't include a backend.
Instead, authentication actions are exposed through async/throws callbacks. This keeps the UI independent from a specific authentication provider and lets developers connect their own API, Firebase, Supabase, or another service.
This was an important lesson for me: a reusable UI component shouldn't force every project to use the same backend.
What I learned
The biggest thing I learned from this project is that making something reusable requires thinking differently from building a screen for one specific app.
I had to think about validation, configuration, different UI states, customization and how another developer would actually integrate the code.
I'm still learning Swift and SwiftUI, so I'd love to hear how more experienced iOS developers would structure something like this differently.
The finished project
I turned the project into a downloadable SwiftUI template called ModernLogin. It includes the complete editable Swift source code and documentation.
It's available for $14.99 on Gumroad:
https://raimond77.gumroad.com/l/modern-auth-swiftui
If you have any feedback on the architecture, UI, or what you'd expect from a reusable authentication template, I'd really appreciate it.
Top comments (0)