Skip to content
Closed
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
19 changes: 19 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Google Maps Configuration
VITE_GOOGLE_MAPS_API_KEY=AIzaSyA8G_comPVj6E68kfw6jjyJH8mZmiNI7s8

# API Configuration
VITE_API_BASE_URL=http://localhost:8000
VITE_API_TIMEOUT=30000

# API Endpoints
VITE_USER_ENDPOINT_PATH=/api/v1/users
VITE_PORTS_ENDPOINT_PATH=/api/v1/ports
VITE_PORT_CONNECTIONS_ENDPOINT_PATH=/api/v1/port-connections
VITE_ROUTES_ENDPOINT_PATH=/api/v1/routes
VITE_EXPORTS_ENDPOINT_PATH=/api/v1/exports
VITE_ALGORITHMS_ENDPOINT_PATH=/api/v1/algorithms
VITE_OPTIMIZATION_ENDPOINT_PATH=/api/v1/routes/compute

# Application Settings
VITE_APP_NAME=BerrySend
VITE_APP_VERSION=1.0.0
20 changes: 20 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Google Maps Configuration
VITE_GOOGLE_MAPS_API_KEY=AIzaSyDWlqL8kfdt5AwSYU1tXzPJM3NTXTkEuUM

# API Configuration
VITE_API_BASE_URL=https://fake-api-4n0p.onrender.com
VITE_API_TIMEOUT=30000

# API Endpoints
VITE_USER_ENDPOINT_PATH=/api/v1/users
VITE_PORTS_ENDPOINT_PATH=/api/v1/ports
VITE_PORT_CONNECTIONS_ENDPOINT_PATH=/api/v1/port-connections
VITE_ROUTES_ENDPOINT_PATH=/api/v1/routes
VITE_EXPORTS_ENDPOINT_PATH=/api/v1/exports
VITE_ALGORITHMS_ENDPOINT_PATH=/api/v1/algorithms
VITE_OPTIMIZATION_ENDPOINT_PATH=/api/v1/routes/compute

# Application Settings
VITE_APP_NAME=BerrySend
VITE_APP_VERSION=1.0.0

14 changes: 14 additions & 0 deletions .firebase/hosting.ZGlzdA.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
index.html,1763958181407,0e3f1452c1209fb8c1e90faf9b6c3709bccffa623982d6eed47cb347f582eb3c
assets/visualization-page-qcryGJmo.css,1763958181406,8ff4683adad504937d2350f56ba3ee0fd52f06fce090c1aad940ed8b9be81066
assets/port-page-CQhjS9DO.css,1763958181406,d39e26e9bc98df07137800aaa3000a3ad1e9ca3d2ac0e283d18b5ec572088a26
assets/port-page.component-C6ddnWAC.js,1763958181407,f3cc824aba69a9e17b72cc535858c4be6c3ae99b01611e74e1ca35f169044a7d
assets/optimization-page-JblpntI1.css,1763958181406,7fa970e03835678644d840c533c2476557319dcf24101fd8cd4e419af2660006
favicon.ico,1762229037809,3d3d5c038cc96d71c43ffff92b9bf099f92adf9d867d0849ddcc2086c63c907b
assets/visualization-page.component-CmK1zWoj.js,1763958181407,1de1713c5b41f0a3c03da0d33a79200a33e2fd900f5eea0242c9736b9bdd37b4
assets/optimization-page.component-DUNAYf-F.js,1763958181407,af16d65b8cf07c78709d8c71d1d35b923d8850bd6b5b79c29b83909505fc21e1
assets/register-page.component-CcraQaLq.js,1763958181407,a728313ff3c4c5766db0d0361d7a32b97258bc27db5c77f5b4ca1284eb0eecdb
assets/login-page.component-B0bs8AnG.js,1763958181407,5e41d404955dfdf2ae1bcfb59baab7845cef75a36d20ca64c0b6711f16410837
assets/auth-layout-BLnr3ucQ.css,1763958181406,eafccf5f100313bdc38848105396d8df3ad29e2c7f33dba30a0576005c84ebdc
assets/auth-layout.component-DMnwoECF.js,1763958181407,228ffdff2cf00305fec3db564da9671a3c6d1492b0a2fca8baefc8152aff6f93
assets/index-C4Hm7WUM.css,1763958181406,a31df13b16f6b10cf19ad35c87f145ce0d560b230248af3c30ae76fa02aef28f
assets/index-DApqfwZF.js,1763958181407,30e74153ac3146b4256b7b2b86a0328423f74d29ac4cc77c110cd1b9502b384d
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "berrysend-app"
}
}
20 changes: 20 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
on:
push:
branches:
- develop
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BERRYSEND_APP }}
channelId: live
projectId: berrysend-app
21 changes: 21 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
on: pull_request
permissions:
checks: write
contents: read
pull-requests: write
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BERRYSEND_APP }}
projectId: berrysend-app
135 changes: 135 additions & 0 deletions API_URL_CHANGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# ✅ Cambio de API Completado

## 🔄 Lo Que Se Cambió

Se ha actualizado la URL de la API de `localhost:3000` a la API en la nube:

```
❌ ANTES: http://localhost:3000
✅ AHORA: https://fake-api-4n0p.onrender.com
```

## 📝 Archivos Actualizados

### `.env.development`
```env
# Antes
VITE_API_BASE_URL=http://localhost:3000

# Ahora
VITE_API_BASE_URL=https://fake-api-4n0p.onrender.com
```

## 🚀 Próximos Pasos

### 1. Reinicia el servidor
```bash
npm run dev
```

### 2. Verifica la conexión
- Abre la consola (F12)
- Ejecuta:
```javascript
quickConfigCheck()
```

**Deberías ver:**
```
🔧 BerrySend Config Check
API: https://fake-api-4n0p.onrender.com
Ports: https://fake-api-4n0p.onrender.com/api/v1/ports
Exports: https://fake-api-4n0p.onrender.com/exports
✅ Config OK
```

## ⚙️ Cómo Funciona

El sistema ahora usa esta estructura:

```
1. Tu navegador
2. Aplicación BerrySend (http://localhost:5173)
3. API en la nube (https://fake-api-4n0p.onrender.com)
4. Base de datos
```

## 🔐 Cambios en Diferentes Ambientes

### Desarrollo (Development)
```env
VITE_API_BASE_URL=https://fake-api-4n0p.onrender.com
```

### Producción (Production) - OPCIONAL
Si necesitas cambiar también la producción, edita `.env.production`

## ✨ Ventajas

✅ **API en la nube** - No necesitas servidor local
✅ **Mismo endpoint** para todos
✅ **Escalable** - La API puede crecer sin afectar tu código
✅ **HTTPS** - Conexión segura

## 🔍 Verificación

Después de reiniciar el servidor, verifica:

1. **Conectividad**: Los datos deben cargar sin errores
2. **Consola**: No debe haber errores de CORS o conexión
3. **Funcionalidad**: Todas las páginas deben funcionar normalmente

## 📊 Endpoints Disponibles

Tu aplicación usará estos endpoints:

```
✅ https://fake-api-4n0p.onrender.com/api/v1/ports
✅ https://fake-api-4n0p.onrender.com/api/v1/port-connections
✅ https://fake-api-4n0p.onrender.com/exports
✅ https://fake-api-4n0p.onrender.com/algorithms
✅ https://fake-api-4n0p.onrender.com/api/v1/routes/compute
```

## ⚡ Cambios Rápidos

### Si necesitas volver a localhost
```env
VITE_API_BASE_URL=http://localhost:3000
```

### Si necesitas otra URL
```env
VITE_API_BASE_URL=https://tu-api-url.com
```

Solo edita `.env.development` y reinicia el servidor.

## 📞 Troubleshooting

### Problema: CORS Error
**Solución:** La API en la nube debe permitir CORS desde tu dominio

### Problema: Timeout
**Solución:** Aumenta el timeout en `.env.development`:
```env
VITE_API_TIMEOUT=60000
```

### Problema: Datos no cargan
**Solución:** Verifica que la URL sea correcta:
```javascript
// En consola
import.meta.env.VITE_API_BASE_URL
// Debe mostrar: https://fake-api-4n0p.onrender.com
```

---

**Estado:** ✅ COMPLETADO
**Fecha:** 23 de Noviembre, 2025
**API:** https://fake-api-4n0p.onrender.com

16 changes: 16 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
84 changes: 52 additions & 32 deletions src/auth/services/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @module modules/auth/services/authService
*/

import axios from 'axios';
import {User} from "@/auth/model/user.entity.js";
import {AuthToken} from "@/auth/model/auth-token.entity.js";
import userService from "@/auth/services/user.service.js";
import { buildApiUrl, getApiTimeout } from '@/config/environment.js';

/**
* Auth Service class for API interactions
Expand All @@ -24,33 +25,42 @@ class AuthService {
*/
async login(email, password) {
try {
// Use userService to find user directly from db.json
const user = await userService.findByEmailAndPassword(email, password);

if (!user) {
throw new Error('Invalid email or password');
}
const response = await axios.post(
`${buildApiUrl('auth')}/sign-in`,
{ email, password },
{ timeout: getApiTimeout() }
);

// Generate mock token
const data = response.data;

// Backend response: { id, full_name, email, token }
const token = AuthToken.fromAPI({
accessToken: `mock_token_${Date.now()}`,
refreshToken: `mock_refresh_${Date.now()}`,
expiresIn: 3600,
accessToken: data.token,
refreshToken: '',
expiresIn: 1800, // 30 minutes
tokenType: 'Bearer',
createdAt: new Date().toISOString()
});

const user = User.fromAPI({
id: data.id,
name: data.full_name,
email: data.email
});

return {
token,
user
};
} catch (error) {
console.error('Error during login:', error);

if (error.message === 'Invalid email or password') {
throw error;
if (error.response?.status === 400) {
throw new Error('Invalid email or password');
}
throw new Error('Failed to login. Please try again.');

const errorMessage = error.response?.data?.detail || 'Failed to login. Please try again.';
throw new Error(errorMessage);
}
}

Expand All @@ -67,34 +77,44 @@ class AuthService {
*/
async register(userData) {
try {
// Use userService to create user directly in db.json
const user = await userService.create({
email: userData.email,
password: userData.password,
name: userData.name,
role: 'user'
});
const response = await axios.post(
`${buildApiUrl('auth')}/sign-up`,
{
full_name: userData.name,
email: userData.email,
password: userData.password,
confirm_password: userData.password
},
{ timeout: getApiTimeout() }
);

// Generate mock token
const token = AuthToken.fromAPI({
accessToken: `mock_token_${Date.now()}`,
refreshToken: `mock_refresh_${Date.now()}`,
expiresIn: 3600,
tokenType: 'Bearer',
createdAt: new Date().toISOString()
const data = response.data;

// Backend response: { id, full_name, email } (no token in sign-up)
// User needs to login after registration
const user = User.fromAPI({
id: data.id,
name: data.full_name,
email: data.email
});

// No token returned from sign-up, return null token
return {
token,
token: null,
user
};
} catch (error) {
console.error('Error during registration:', error);

if (error.message === 'Email already exists') {
throw error;
if (error.response?.status === 400) {
const errorDetail = error.response?.data?.detail;
if (typeof errorDetail === 'string' && errorDetail.includes('already')) {
throw new Error('Email already registered');
}
}
throw new Error('Failed to register. Please try again.');

const errorMessage = error.response?.data?.detail || 'Failed to register. Please try again.';
throw new Error(errorMessage);
}
}

Expand Down
Loading
Loading