Essential security, quality, and debugging considerations for vibe coding
AI-generated code may work but not be secure. Always check these 5 issues.
AI often puts API keys directly in example code.
// Dangerous
const supabase = createClient(
"https://abc.supabase.co",
"eyJhbGciOiJIUzI1NiIs..."
);
// Safe
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);Never hardcode API keys, secrets, or passwords in code.
Always use environment variables (.env.local).
AI sometimes builds SQL through string concatenation.
// Dangerous: string concatenation
const query = `SELECT * FROM users WHERE name LIKE '%${userInput}%'`;
// Safe: parameterized queries
const { data } = await supabase
.from('users')
.ilike('name', `%${userInput}%`);Rendering user input directly as HTML is dangerous.
// Dangerous
<div dangerouslySetInnerHTML={{ __html: userComment }} />
// Safe: React's default escaping
<div>{userComment}</div>
// When HTML needed: use sanitize library
import DOMPurify from 'dompurify';
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userComment) }} />// Dangerous: allow all origins
const corsHeaders = { "Access-Control-Allow-Origin": "*" };
// Safe: specific domain only
const corsHeaders = {
"Access-Control-Allow-Origin": "https://myapp.vercel.app"
};// Dangerous: no validation
export async function POST(req: Request) {
const { email, amount } = await req.json();
await chargeUser(email, amount); // What if amount is negative?
}
// Safe: Zod validation
import { z } from 'zod';
const schema = z.object({
email: z.string().email(),
amount: z.number().positive().max(1000000),
});
export async function POST(req: Request) {
const body = schema.parse(await req.json());
await chargeUser(body.email, body.amount);
}The biggest vibe coding trap is "it works, let's move on". AI-generated code that works isn't necessarily good code.
Use this prompt periodically:
"Review all the code written so far.
Find code duplication, unnecessary dependencies, performance issues, and structural problems."
When you ask AI for features, it often doesn't write tests. You must explicitly ask.
> "Build a login API. Write unit tests too:
- Successful login case
- Wrong password case
- Non-existent email case"AI tends to generate repetitive patterns. If you see 100 lines of similar code across 5 files, abstraction is needed.
> "Extract common patterns from these 5 files into reusable utility functions"> "I'm getting this error:
[Full error message copy]
Fix it."This solves 80% of problems.
If the error message alone isn't enough:
> "Read lib/auth.ts and app/api/login/route.ts,
and analyze why authentication is failing."If the same approach keeps failing:
> "This approach keeps failing. Implement it with a completely different approach.
Delete the previous code and start from scratch."If AI keeps making the same fix without solving the problem:
/clear or new session)When Claude Code keeps editing the same file without fixing it:
Ctrl+C to stopgit diff to check changesgit checkout -- [file] to revertWhen AI recommends a library, verify before installing:
| Check Item | Safe Threshold |
|---|---|
| Weekly downloads | 10,000+ |
| Last updated | Within 6 months |
| GitHub stars | 1,000+ |
| Open issues | 50%+ resolution rate |
| License | MIT, Apache 2.0, BSD |
AI sometimes makes up package names that don't actually exist (hallucination). If npm install fails, first verify the package actually exists.
| Situation | Vibe Coding | Manual Coding |
|---|---|---|
| New project scaffolding | O | |
| Repetitive CRUD | O | |
| UI component creation | O | |
| Complex algorithms | O | |
| Performance optimization | O | |
| Large-scale refactoring | O | |
| Security-critical logic | O | |
| Understanding existing code | O (ask for explanation) |
If you don't understand vibe-coded output:
Build quickly with vibe coding, but ask AI to explain the core parts:
"Explain the authentication logic you just built in beginner-friendly terms.
What each function does and how data flows through it."
This gives you both vibe coding speed and actual learning.
Check these before deploying your project: