Skip to content

Commit

Permalink
Fixes langgenius#11065: tenant_id not found when login via ADMIN_KEY (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
lotabout authored Nov 27, 2024
1 parent 41c6bf5 commit 6f418da
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from flask import Flask, Response, request
from flask_cors import CORS
from flask_login import user_loaded_from_request, user_logged_in
from werkzeug.exceptions import Unauthorized

import contexts
Expand Down Expand Up @@ -120,11 +121,17 @@ def load_user_from_request(request_from_flask_login):
user_id = decoded.get("user_id")

logged_in_account = AccountService.load_logged_in_account(account_id=user_id)
if logged_in_account:
contexts.tenant_id.set(logged_in_account.current_tenant_id)
return logged_in_account


@user_logged_in.connect
@user_loaded_from_request.connect
def on_user_logged_in(_sender, user):
"""Called when a user logged in."""
if user:
contexts.tenant_id.set(user.current_tenant_id)


@login_manager.unauthorized_handler
def unauthorized_handler():
"""Handle unauthorized requests."""
Expand Down

0 comments on commit 6f418da

Please sign in to comment.