You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://codecov.io/gh/nim444/fastapi-auth-multi-db)<!-- Assuming Codecov is setup -->
8
9
9
-
A robust FastAPI application demonstrating user registration, JWT authentication, and a flexible repository pattern supporting SQLite, PostgreSQL, and MongoDB backends.
10
+
A robust FastAPI application demonstrating user registration, JWT authentication (including refresh tokens), and a flexible repository pattern supporting SQLite, PostgreSQL, and MongoDB backends.
10
11
11
12
## Purpose
12
13
@@ -21,12 +22,13 @@ This project serves as a template or starting point for building secure and scal
@@ -94,10 +97,11 @@ This project serves as a template or starting point for building secure and scal
94
97
# Install DB-specific drivers if needed (not included by default)
95
98
# uv pip install psycopg2-binary # For PostgreSQL
96
99
# uv pip install motor # For MongoDB
100
+
# uv pip install aiosqlite # For async SQLite
97
101
```
98
102
99
103
4. **Configure Settings:**
100
-
* Settings are managed by `Dynaconf`, loading from `config/settings.toml`, `config/.secrets.toml`, and environment variables.
104
+
* Settings are managed by `Dynaconf`, loading from `config/settings.toml`, `config/.secrets.toml`, and environment variables (prefixed with `FAPI_`, e.g., `FAPI_DATABASE_TYPE`, `FAPI_JWT_SECRET_KEY`).
101
105
***Create `config/.secrets.toml`** by copying `config/.secrets.toml.example`. Add your `JWT_SECRET_KEY` (must be strong and secret). **Do not commit `.secrets.toml`**.
102
106
103
107
```toml
@@ -116,18 +120,11 @@ This project serves as a template or starting point for building secure and scal
116
120
* If using MongoDB, set`mongo_db_name`.
117
121
118
122
5. **Initialize Database:**
119
-
***SQL (SQLite/PostgreSQL):** This project uses Alembic for migrations.
123
+
***SQL (SQLite/PostgreSQL):** This project includes `alembic` as a dependency for potential migrations.
120
124
* Ensure your database exists.
121
-
* Run migrations: `alembic upgrade head`
122
-
**(You might need to configure Alembic first if not already set up - check for an `alembic.ini` file and a `migrations/` directory)*
123
-
***MongoDB:** Ensure unique indexes are created for the `users` collection (username, email). This can be done manually or added to the application startup logic.
124
-
125
-
```javascript
126
-
// Example in MongoDB shell:
127
-
use your_db_name; // As defined in settings.toml (mongo_db_name)
* If you have Alembic migrations set up (e.g., `alembic.ini` file and a `migrations/` directory), run: `alembic upgrade head`
126
+
**(If Alembic is not fully configured, you may need to initialize it or manage schema changes manually)*
127
+
***MongoDB:** Ensure your MongoDB server is running. The application will automatically attempt to create the required unique indexes forthe `users` collection (on `username` and `email`) when it starts up, using the database name specified by `mongo_db_name`in your settings.
Coverage report will be in the `htmlcov/` directory.
164
161
162
+
## Running GitHub Actions Locally (Optional)
163
+
164
+
If you have `act` installed, you can simulate GitHub Actions workflows locally. This is particularly useful for testing CI/CD pipelines before pushing changes.
165
+
166
+
```bash
167
+
# Run workflows, specifying architecture if needed (e.g., for M1/M2 Macs)
168
+
act --container-architecture linux/amd64
169
+
```
170
+
165
171
## API Documentation
166
172
167
173
Once the server is running, access the interactive API documentation:
@@ -180,15 +186,3 @@ Once the server is running, access the interactive API documentation:
180
186
4. If switching to SQL, ensure the database exists and migrations are applied (`alembic upgrade head`).
181
187
5. If switching to MongoDB, ensure indexes exist.
182
188
6. Restart the application: `uvicorn main:app --reload ...`
183
-
184
-
<!-- Badges Definitions (Update URLs as needed) -->
0 commit comments