fix: preserve user token for FB page discovery after page selection
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
After selecting a FB page, the user token was overwritten with page token. me/accounts requires user token to list pages, so page discovery returned empty. Now stores user_access_token in oauth metadata_json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3d13f41878
commit
ed60643ec6
@ -246,12 +246,24 @@ def oauth_discover_fb_pages():
|
||||
oauth = OAuthService()
|
||||
db = SessionLocal()
|
||||
try:
|
||||
token = oauth.get_valid_token(db, company_id, 'meta', 'facebook')
|
||||
if not token:
|
||||
# Need user token (not page token) to list managed pages via me/accounts
|
||||
from database import OAuthToken
|
||||
oauth_token = db.query(OAuthToken).filter(
|
||||
OAuthToken.company_id == company_id,
|
||||
OAuthToken.provider == 'meta',
|
||||
OAuthToken.service == 'facebook',
|
||||
OAuthToken.is_active == True,
|
||||
).first()
|
||||
|
||||
if not oauth_token:
|
||||
return jsonify({'success': False, 'error': 'Brak połączenia Facebook dla tej firmy'}), 404
|
||||
|
||||
# Use user token from metadata if available (page token can't list pages)
|
||||
meta = oauth_token.metadata_json or {}
|
||||
user_token = meta.get('user_access_token') or oauth_token.access_token
|
||||
|
||||
from facebook_graph_service import FacebookGraphService
|
||||
fb = FacebookGraphService(token)
|
||||
fb = FacebookGraphService(user_token)
|
||||
pages = fb.get_managed_pages()
|
||||
|
||||
return jsonify({
|
||||
@ -328,6 +340,12 @@ def oauth_select_fb_page():
|
||||
).first()
|
||||
|
||||
if oauth_token:
|
||||
# Preserve user token in metadata for future page discovery
|
||||
meta = oauth_token.metadata_json or {}
|
||||
if not meta.get('user_access_token'):
|
||||
meta['user_access_token'] = oauth_token.access_token
|
||||
oauth_token.metadata_json = meta
|
||||
|
||||
oauth_token.access_token = page_access_token
|
||||
oauth_token.account_id = str(page_id)
|
||||
oauth_token.account_name = page_name
|
||||
|
||||
Loading…
Reference in New Issue
Block a user