Auth — 3 instances Better Auth sur 1 Postgres¶
Authentification centralisée via Better Auth (projects/api/src/lib/better-auth/). Sessions stockées dans Postgres (better_auth_*).
Migration historique investisseurs : Migration auth investisseurs (Better Auth).
Diagramme¶
flowchart LR
subgraph apps["Applications"]
m["Mobile / Web invest"]
p["PDP"]
bo["Back-offices"]
end
subgraph auth["Better Auth"]
client["clientAuth<br/>/api/auth/*"]
admin["adminAuth<br/>/api/auth/admin/*"]
end
subgraph storage["Postgres Neon"]
pg[("better_auth_*")]
end
m --> client
p --> client
legacy["front-app"] --> client
bo --> admin
client --> pg
admin --> pg
clientAuth¶
| Route | /api/auth/* |
| Cookie | better-auth.session_token |
| Apps | front-mobile-app, front-app, app-pdp-financement |
| Utilisateurs | Investisseurs + porteurs de projet |
Fonctionnalités : email/password, OAuth (Google, Facebook, LinkedIn, Apple), 2FA OTP (Customer.io), vérification email, reset password, plugin Expo (mobile).
Transport front :
- Web : cookies (
withCredentials: true) - Natif : cookie header depuis SecureStore
adminAuth¶
| Route | /api/auth/admin/* |
| Cookie | bricks-admin.session_token |
| Apps | bricksoffice-invest, bricksoffice-projects |
| Utilisateurs | Admins (role === 'admin') |
Guards API¶
| Guard | Fichier | Usage |
|---|---|---|
JwtAuthGuard |
customer-auth/customer-auth.guard.ts |
Routes investisseur — session → customers |
AdminAuthGuard |
admin-auth/admin-auth.guard.ts |
Routes admin |
AuthGuard (nestjs-better-auth) |
PDP pdp-auth.controller.ts |
/project-owner/me |
ApiAuthService |
__new/lib/api-auth/ |
Webhooks et M2M |
MFA legacy (actions sensibles post-login) : POST /auth/mfa/* (Redis) — distinct du 2FA Better Auth à la connexion.
API keys¶
Auth par x-api-key ou apiKey query (comparaison timing-safe).
| Consommateur | Usage | Owner |
|---|---|---|
lemonway |
Webhooks | À compléter |
checkout |
Webhooks CB | À compléter |
customer-io |
À compléter | À compléter |
espace-financement |
Bridge legacy Bubble | À compléter |
| Outils internes | gestion-defauts, projet-analyse, ia-whatsapp, ai-agent, site-vitrine |
À compléter |
Stockage / rotation des clés côté ops : À compléter.
Matrice app → instance¶
| Application | Instance | Mécanisme session |
|---|---|---|
| front-mobile-app | clientAuth | Cookie web / header natif |
| front-app | clientAuth | Cookie |
| app-pdp-financement | clientAuth | Cookie |
| bricksoffice-invest | adminAuth | Cookie admin |
| bricksoffice-projects | adminAuth | Cookie admin |
À compléter¶
| Sujet | Notes |
|---|---|
| Durée session / refresh | À compléter |
| Politique impersonation admin | À compléter |
| SSO / SAML entreprise | À compléter si applicable |
| Matrice routes sensibles + 2FA legacy | À compléter |