phase1: fix auth_service tenant context for audit_log, add sessions+audit_log to crm_auth grants

- auth_service.py: set tenant context before audit log write in login
- migration 0085: add sessions and audit_log to AUTH_TABLES for crm_auth
- Login now works on production with RLS enabled
This commit is contained in:
Agent Zero
2026-07-31 02:28:29 +02:00
parent 100b9f705c
commit 15f0a07d4e
2 changed files with 6 additions and 0 deletions
@@ -77,6 +77,8 @@ AUTH_TABLES = {
"user_tenants": ["SELECT"],
"tenants": ["SELECT"],
"password_reset_tokens": ["SELECT", "INSERT", "UPDATE", "DELETE"],
"sessions": ["SELECT", "INSERT", "UPDATE", "DELETE"],
"audit_log": ["SELECT", "INSERT"],
}
WORKER_GLOBAL_TABLES = {
+4
View File
@@ -109,6 +109,10 @@ class AuthService:
db, redis, user, tenant.id, role=user_tenant.role
)
# Set tenant context for audit log write (auth session uses crm_auth role)
from app.core.db import set_tenant_context
await set_tenant_context(db, tenant.id)
# Log the login in audit trail
await log_audit(
db,