Stop Vibe-Coding Your Authentication for AI Projects
Avoid common pitfalls and design a secure login system that keeps users happy and your data safe
For AI builders, PMs, and vibe-coders who want to get authentication right without reinventing the wheel.
For AI projects, secure authentication and token management might seem like plumbing, but they’re absolutely crucial.
Users expect to stay signed in across tabs, devices, and sessions. A clunky login experience can break engagement before your model even gets a chance to shine.
When I built my first AI product, CantoAI, users were getting logged out every hour. I had to rethink authentication for both security and user experience.
In this post, I’ll show you the design, pitfalls, and best practices behind secure AI authentication.
Why Auth Goes Wrong in Many AI Apps
It’s tempting to “vibe-code” authentication quickly and move on, but cutting corners can create frustration and even serious security risks.
Common pitfalls include:
Short-lived sessions without refresh: Users get logged out constantly.
Storing Tokens incorrectly: Mishandling tokens can expose your site to XSS (cross-site scripting) attacks, where malicious scripts can hijack accounts.
No rate limiting: Attackers could repeatedly guess credentials or abuse sessions.
A poorly designed auth system frustrates users and creates attack surfaces, which is especially dangerous for AI apps handling sensitive data or long-running sessions.
Leveraging Supabase for Authentication
Authentication is tricky: encryption, token refresh cycles, and credential storage are complex. I chose to use Supabase because it handles all of this out of the box.
While Supabase started as a Postgres database provider, it has expanded its offerings to include a full suite of backend services, including:
Authentication
Storage
Real-time subscriptions
It supports email/password, social logins (Google, GitHub), passwordless magic links, and OTPs.
Its free tier includes up to 50k monthly active users and unlimited API requests. This makes it perfect for AI builders and “vibe-coders” who want robust auth without headaches or high costs.
Design Choices: Balancing Security and Simplicity
I wanted a secure and seamless login experience, keeping users logged in while keeping sensitive tokens safe. I separated responsibilities between frontend, backend, and Supabase:
Frontend: Starts login, checks session state, never exposes tokens.
Backend (FastAPI): Handles token exchange, stores tokens securely in cookies, validates sessions, and enforces rate limits.
Supabase: Issues and refreshes tokens, verifies users, and manages OAuth flows.
This design gives me a system that’s secure and maintainable, without needing to be an auth expert.
Key Lessons Learned
Third-party providers save time and reduce headaches. For AI builders, here are the main takeaways:
Separate concerns: Frontend handles interface, backend handles security, Supabase handles auth.
Use refresh tokens: Keep users logged in without sacrificing security.
Cookies: Protect tokens from malicious scripts.
These principles let you focus on building your AI project, not reinvent authentication.
How do you handle authentication in your AI projects? Have you run into token, session, or login headaches that caused user frustration?



I used Supabase auth for my first “real” project. It was soooo easy (only a few issues with the connection to Resend, my email api). I’ve heard Clerk is good too. But I imagine the integration into a crud db is super powerful.
https://open.substack.com/pub/khemaridh/p/i-coded-an-entire-crm-from-scratch?r=bf55&utm_medium=ios
Thanks for the post. I wasn’t aware supabase did auth. I’ll definitely look into that.