From 059aa5e9136b60d0e9ed46675bb09387a5291520 Mon Sep 17 00:00:00 2001 From: Scobiform Date: Wed, 17 Apr 2024 21:29:48 +0200 Subject: [PATCH] #1 fetch on client side --- start.py | 13 +++++++++++-- templates/graph.html | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/start.py b/start.py index 85c3c4f..9694d7f 100644 --- a/start.py +++ b/start.py @@ -89,8 +89,17 @@ async def setup_app(): @app.route('/') async def home(): if 'access_token' in session: - # Pass minimal data to the client to fetch data - return await render_template('index.html', logged_in=True, api_base_url=config['instance_url'], user_id=session['user_id']) + # Initialize Mastodon with the access token + mastodon = Mastodon( + access_token=session['access_token'], + api_base_url=config['instance_url'] + ) + + # Fetch the authenticated user + user = mastodon.account_verify_credentials() + + # Pass data to the template + return await render_template('index.html', logged_in=True, user=user) else: # Render the template without user data return await render_template('index.html', logged_in=False) diff --git a/templates/graph.html b/templates/graph.html index f066c67..ab3f5f0 100644 --- a/templates/graph.html +++ b/templates/graph.html @@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', function() { const apiBaseUrl = '{{ api_base_url }}'; const accessToken = sessionStorage.getItem('accessToken'); // Ensure this is stored securely - const userId = '{{ user_id }}'; + const userId = '{{ user.id }}'; Promise.all([ fetchAllItems(userId, 'followers'),