diff --git a/server/index.js b/server/index.js index cb1f33c..ee3c108 100644 --- a/server/index.js +++ b/server/index.js @@ -124,7 +124,7 @@ try { const projectId = process.env.FIREBASE_PROJECT_ID; const clientEmail = process.env.FIREBASE_CLIENT_EMAIL; const rawPrivateKey = process.env.FIREBASE_PRIVATE_KEY; - const privateKey = rawPrivateKey ? rawPrivateKey.replaceAll(String.raw`\n`, '\n') : undefined; + const privateKey = rawPrivateKey ? rawPrivateKey.replaceAll('\\n', '\n') : undefined; if (projectId && clientEmail && privateKey) { if (!admin.apps.length) { @@ -179,7 +179,15 @@ const otpResetSchema = z.object({ }); const normalizeEmail = (email) => email.trim().toLowerCase(); -const normalizePhone = (phone) => phone.replaceAll(/\D/g, ''); +const normalizePhone = (phone) => { + const digits = phone.replaceAll(/\D/g, ''); + const minLen = 6; + const maxLen = 32; + if (digits.length < minLen || digits.length > maxLen) { + throw new Error('Normalized phone number has invalid length.'); + } + return digits; +}; const normalizeAddress = (address) => { if (typeof address !== 'string' || !address.startsWith('0x')) { diff --git a/services/firebaseClient.ts b/services/firebaseClient.ts index 28062a5..37d089c 100644 --- a/services/firebaseClient.ts +++ b/services/firebaseClient.ts @@ -22,8 +22,9 @@ import { type UserCredential, } from 'firebase/auth'; -let firebaseApp: FirebaseApp | null | undefined; -let firebaseAuth: Auth | null | undefined; +let firebaseApp: FirebaseApp | null = null; +let firebaseAuth: Auth | null = null; +let firebaseInitialized = false; const loadFirebaseConfig = () => { const apiKey = import.meta.env.VITE_FIREBASE_API_KEY; @@ -50,12 +51,13 @@ const loadFirebaseConfig = () => { }; const ensureFirebase = (): { app: FirebaseApp; auth: Auth } | null => { - if (firebaseAuth !== undefined && firebaseApp !== undefined) { + if (firebaseInitialized) { if (firebaseApp && firebaseAuth) { return { app: firebaseApp, auth: firebaseAuth }; } return null; } + firebaseInitialized = true; const config = loadFirebaseConfig(); if (!config) { diff --git a/services/geminiService.ts b/services/geminiService.ts index d437775..f29ec47 100644 --- a/services/geminiService.ts +++ b/services/geminiService.ts @@ -263,7 +263,7 @@ const blobToBase64 = (blob: Blob): Promise => { const bytes = new Uint8Array(result); let binary = ''; for (let i = 0; i < bytes.byteLength; i++) { - binary += String.fromCodePoint(bytes[i]); + binary += String.fromCharCode(bytes[i]); } resolve(btoa(binary)); } else { diff --git a/utils/metadata.ts b/utils/metadata.ts index 550695c..c4bf97c 100644 --- a/utils/metadata.ts +++ b/utils/metadata.ts @@ -35,7 +35,7 @@ const fromBase64 = (value: string) => { const binary = globalThis.atob(value); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { - bytes[i] = binary.codePointAt(i) ?? 0; + bytes[i] = binary.charCodeAt(i); } return new TextDecoder().decode(bytes); } diff --git a/vite.config.ts b/vite.config.ts index b11c714..e24f876 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,9 +3,11 @@ import path from 'node:path'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +// Set production base path via environment variable VITE_PROD_BASE_PATH, falling back to default if not set. +const PROD_BASE_PATH = process.env.VITE_PROD_BASE_PATH || '/Fractal-Recipe-Generator/'; export default defineConfig(({ mode }) => { const isProduction = mode === 'production'; - const basePath = isProduction ? '/Fractal-Recipe-Generator/' : '/'; + const basePath = isProduction ? PROD_BASE_PATH : '/'; return { base: basePath, server: {