Skip to content

Commit

Permalink
#1 fetch on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Scobiform committed Apr 17, 2024
1 parent 1742b92 commit 059aa5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion templates/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 059aa5e

Please sign in to comment.