fix: Address CodeRabbit review comments for PR #90

- Add try/except for invalid credits metadata in stripe_service.py
- Fix race condition in magic link verification with Firestore transaction
- Move @import before @tailwind directives in globals.css (CSS spec)
- Fix broken Open Graph image URL in layout.tsx
- Remove insecure fallback admin privileges in auth.ts
- Bump version to 0.76.26

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Andrew BeveridgeandClaude Opus 4.5 committed 2025-12-28 03:58:07 -05:00
1 parent b204f28d50
commit ebb9503bde
6 files changed
+52 -38

No files matched your search

+5 -1
View File
@@ -182,7 +182,11 @@ class StripeService:
try:
metadata = session.get('metadata', {})
user_email = metadata.get('user_email') or session.get('customer_email')
credits = int(metadata.get('credits', 0))
try:
credits = int(metadata.get('credits', 0))
except (ValueError, TypeError):
logger.error(f"Invalid credits metadata in session {session.get('id')}: {metadata.get('credits')}")
return False, user_email, 0, "Invalid credit amount in session metadata"
package_id = metadata.get('package_id')
if not user_email:
+35 -22
View File
@@ -176,49 +176,62 @@ class UserService:
def verify_magic_link(self, token: str) -> Tuple[bool, Optional[User], str]:
"""
Verify a magic link token.
Verify a magic link token using a Firestore transaction to prevent race conditions.
Returns:
(success, user, message)
"""
try:
doc_ref = self.db.collection(MAGIC_LINKS_COLLECTION).document(token)
doc = doc_ref.get()
if not doc.exists:
return False, None, "Invalid or expired link"
@firestore.transactional
def verify_in_transaction(transaction):
"""Atomically verify and mark magic link as used."""
doc = doc_ref.get(transaction=transaction)
magic_link = MagicLinkToken(**doc.to_dict())
if not doc.exists:
return False, None, "Invalid or expired link"
# Check if already used
if magic_link.used:
return False, None, "This link has already been used"
magic_link = MagicLinkToken(**doc.to_dict())
# Check expiry
if datetime.utcnow() > magic_link.expires_at:
return False, None, "This link has expired"
# Check if already used
if magic_link.used:
return False, None, "This link has already been used"
# Mark as used
doc_ref.update({
'used': True,
'used_at': datetime.utcnow()
})
# Check expiry
if datetime.utcnow() > magic_link.expires_at:
return False, None, "This link has expired"
# Get user and mark email as verified
user = self.get_user(magic_link.email)
# Mark as used atomically within transaction
transaction.update(doc_ref, {
'used': True,
'used_at': datetime.utcnow()
})
return True, magic_link.email, "Success"
# Execute the transaction
transaction = self.db.transaction()
success, email_or_error, message = verify_in_transaction(transaction)
if not success:
return False, None, message
# Get user and mark email as verified (outside transaction)
user = self.get_user(email_or_error)
if user:
self.update_user(
magic_link.email,
email_or_error,
email_verified=True,
last_login_at=datetime.utcnow()
)
user = self.get_user(magic_link.email) # Refresh
user = self.get_user(email_or_error) # Refresh
logger.info(f"Magic link verified for {magic_link.email}")
logger.info(f"Magic link verified for {email_or_error}")
return True, user, "Successfully authenticated"
except Exception as e:
logger.error(f"Error verifying magic link: {e}")
logger.exception(f"Error verifying magic link: {e}")
return False, None, "An error occurred during verification"
# =========================================================================
+2 -2
View File
@@ -1,9 +1,9 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
:root {
--foreground: #f8fafc;
--background: #0f172a;
+1 -1
View File
@@ -13,7 +13,7 @@ export const metadata: Metadata = {
url: 'https://buy.nomadkaraoke.com',
images: [
{
url: 'https://nomadkaraoke.com/logo.png',
url: 'https://gen.nomadkaraoke.com/nomad-logo.png',
width: 512,
height: 512,
alt: 'Nomad Karaoke',
+8 -11
View File
@@ -145,17 +145,14 @@ export const useAuth = create<AuthStore>()(
set({ user, isLoading: false })
return true
} catch {
// Fallback: treat as admin token if it contains 'admin'
// This maintains backwards compatibility
const isAdmin = token.toLowerCase().includes("admin")
const user: User = {
token,
email: 'admin@nomadkaraoke.com',
role: isAdmin ? "admin" : "user",
credits: isAdmin ? 999 : 3,
}
set({ user, isLoading: false })
return true
// Token validation failed - clear token and reject
clearAccessToken()
set({
user: null,
isLoading: false,
error: 'Invalid token or server unavailable'
})
return false
}
},
}),
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.76.25"
version = "0.76.26"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"