Skip to content

Fix demo data population script authentication issues#1

Open
jardahrazdera wants to merge 3 commits intoCodersLab-CZ:mainfrom
jardahrazdera:main
Open

Fix demo data population script authentication issues#1
jardahrazdera wants to merge 3 commits intoCodersLab-CZ:mainfrom
jardahrazdera:main

Conversation

@jardahrazdera
Copy link

Fix demo data population script authentication issues

What was broken

The demo data script (demo_data.py) couldn't create habits after login - kept getting 401 Unauthorized errors even though the user was successfully logged in.

What I did

  • Created a new working script populate_demo.py that properly handles Flask session authentication
  • Fixed cookie security settings in app.py (disabled HTTPS-only cookies for local development)
  • Added proper weekday fields for weekly habits
  • Made the script handle existing users gracefully

Key changes

  1. app.py: Changed SESSION_COOKIE_SECURE from True to False for localhost development
  2. populate_demo.py: New script using requests.Session() to maintain login state (like a browser would)
  3. Added documentation explaining the fix for educational purposes

How to test

cd backend
python populate_demo.py

Then login to the app with demo_user / demo123 and you'll see sample habits with 30 days of tracking data.

Note

I kept the original broken script as demo_data.py for comparison - it's a good example of a common authentication mistake. The working version is populate_demo.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant