Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')) {
Expand Down
6 changes: 3 additions & 3 deletions services/firebaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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;

const loadFirebaseConfig = () => {
const apiKey = import.meta.env.VITE_FIREBASE_API_KEY;
Expand All @@ -50,7 +50,7 @@ const loadFirebaseConfig = () => {
};

const ensureFirebase = (): { app: FirebaseApp; auth: Auth } | null => {
if (firebaseAuth !== undefined && firebaseApp !== undefined) {
if (firebaseAuth !== null && firebaseApp !== null) {
if (firebaseApp && firebaseAuth) {
return { app: firebaseApp, auth: firebaseAuth };
}
Expand Down
2 changes: 1 addition & 1 deletion services/geminiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const blobToBase64 = (blob: Blob): Promise<string> => {
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 {
Expand Down
2 changes: 1 addition & 1 deletion utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading