diff --git a/backend/services/stripe_service.py b/backend/services/stripe_service.py index 7616b58b..c1928137 100644 --- a/backend/services/stripe_service.py +++ b/backend/services/stripe_service.py @@ -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: diff --git a/backend/services/user_service.py b/backend/services/user_service.py index b24dd2df..be817709 100644 --- a/backend/services/user_service.py +++ b/backend/services/user_service.py @@ -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" # ========================================================================= diff --git a/buy-site/app/globals.css b/buy-site/app/globals.css index 33899edc..fcafe9d1 100644 --- a/buy-site/app/globals.css +++ b/buy-site/app/globals.css @@ -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; diff --git a/buy-site/app/layout.tsx b/buy-site/app/layout.tsx index 36b2602c..1a229e33 100644 --- a/buy-site/app/layout.tsx +++ b/buy-site/app/layout.tsx @@ -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', diff --git a/frontend/lib/auth.ts b/frontend/lib/auth.ts index 92a2118e..b98bb588 100644 --- a/frontend/lib/auth.ts +++ b/frontend/lib/auth.ts @@ -145,17 +145,14 @@ export const useAuth = create()( 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 } }, }), diff --git a/pyproject.toml b/pyproject.toml index 01f12159..d3ff0481 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT"