diff --git a/README.md b/README.md index 78da688ad4..5454c492be 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,98 @@ -# WebApp boilerplate with React JS and Flask API - -Build web applications using React.js for the front end and python/flask for your backend API. - -- Documentation can be found here: https://start.4geeksacademy.com/starters/react-flask -- Here is a video on [how to use this template](https://www.loom.com/share/f37c6838b3f1496c95111e515e83dd9b) -- Integrated with Pipenv for package managing. -- Fast deployment to heroku [in just a few steps here](https://start.4geeksacademy.com/backend/deploy-heroku-posgres). -- Use of .env file. -- SQLAlchemy integration for database abstraction. - -### 1) Installation: - -> If you use Github Codespaces (recommended) or Gitpod this template will already come with Python, Node and the Posgres Database installed. If you are working locally make sure to install Python 3.10, Node - -It is recomended to install the backend first, make sure you have Python 3.8, Pipenv and a database engine (Posgress recomended) - -1. Install the python packages: `$ pipenv install` -2. Create a .env file based on the .env.example: `$ cp .env.example .env` -3. Install your database engine and create your database, depending on your database you have to create a DATABASE_URL variable with one of the possible values, make sure you replace the valudes with your database information: - -| Engine | DATABASE_URL | -| --------- | --------------------------------------------------- | -| SQLite | sqlite:////test.db | -| MySQL | mysql://username:password@localhost:port/example | -| Postgress | postgres://username:password@localhost:5432/example | - -4. Migrate the migrations: `$ pipenv run migrate` (skip if you have not made changes to the models on the `./src/api/models.py`) -5. Run the migrations: `$ pipenv run upgrade` -6. Run the application: `$ pipenv run start` - -> Note: Codespaces users can connect to psql by typing: `psql -h localhost -U gitpod example` - -### Undo a migration - -You are also able to undo a migration by running - -```sh -$ pipenv run downgrade -``` - -### Backend Populate Table Users - -To insert test users in the database execute the following command: - +
+ Un proyecto simple de autenticación donde los usuarios pueden registrarse, iniciar sesión y acceder a una página privada protegida. +
+ +--- + +### 🚀 Tecnologías utilizadas +- **Node.js** +- **Express.js** +- **Passport.js** (para la autenticación) +- **JWT (JSON Web Token)** (para la gestión de sesiones) +- **bcryptjs** (para el hashing de contraseñas) +- **EJS** (para la renderización de vistas) +- **MongoDB con Mongoose** (para la base de datos) + +--- + +### 📌 Instalación y Configuración +1. Clonar el repositorio: + ```sh + git clone https://github.com/tu-usuario/nombre-del-repo.git + cd nombre-del-repo + ``` +2. Instalar dependencias: + ```sh + npm install + ``` +3. Configurar las variables de entorno: + - Crear un archivo `.env` en la raíz del proyecto con las siguientes variables: + ```env + PORT=3000 + MONGO_URI=mongodb://localhost:27017/autenticacion + JWT_SECRET=tu_secreto_super_seguro + ``` +4. Iniciar la base de datos (si usas MongoDB localmente): + ```sh + mongod + ``` +5. Ejecutar la aplicación: + ```sh + npm start + ``` + La aplicación estará disponible en `http://localhost:3000` + +--- + +### 🔑 Rutas Principales +- **`GET /`** → Página de inicio +- **`GET /login`** → Formulario de inicio de sesión +- **`POST /login`** → Procesa el inicio de sesión y genera un JWT +- **`GET /register`** → Formulario de registro +- **`POST /register`** → Crea un nuevo usuario +- **`GET /private`** → Página privada (solo accesible con sesión iniciada) +- **`GET /logout`** → Cierra sesión del usuario + +--- + +### 🔐 Autenticación con JWT +Cada usuario autenticado recibirá un **token JWT**, que deberá enviarse en las peticiones a rutas protegidas mediante el encabezado: ```sh -$ flask insert-test-users 5 +Authorization: Bearer