From 236ec2abbe89dd40dd4cf02b299a9603af8493ee Mon Sep 17 00:00:00 2001 From: chelsea Date: Sat, 11 Oct 2025 21:44:13 -0500 Subject: [PATCH] Fix anonymous access 500 error and add environment variable control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed dashboard.html template error accessing current_user.username for anonymous users - Added ALLOW_ANONYMOUS_ACCESS environment variable with default true - Enhanced index route logic to properly check config before allowing anonymous access - Added proper environment variable to docker-compose.yml - Anonymous access now works without 500 server errors Fixes issue #2 completely - anonymous access is now functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app.py | 28 +++++++++++++++++----------- docker-compose.yml | 1 + templates/dashboard.html | 16 ++++++++++++---- templates/post_detail.html | 4 ++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index c2298a3..08a3eac 100644 --- a/app.py +++ b/app.py @@ -42,6 +42,7 @@ app = Flask(__name__, template_folder='templates') app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production') app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size +app.config['ALLOW_ANONYMOUS_ACCESS'] = os.getenv('ALLOW_ANONYMOUS_ACCESS', 'true').lower() == 'true' # Auth0 Configuration app.config['AUTH0_DOMAIN'] = os.getenv('AUTH0_DOMAIN', '') @@ -276,18 +277,23 @@ def index(): return render_template('dashboard.html', user_settings=user_settings) else: - # Anonymous mode - allow browsing with default settings - user_settings = { - 'filter_set': 'no_filter', - 'communities': [], - 'experience': { - 'infinite_scroll': False, - 'auto_refresh': False, - 'push_notifications': False, - 'dark_patterns_opt_in': False + # Check if anonymous access is allowed + if app.config.get('ALLOW_ANONYMOUS_ACCESS', False): + # Anonymous mode - allow browsing with default settings + user_settings = { + 'filter_set': 'no_filter', + 'communities': [], + 'experience': { + 'infinite_scroll': False, + 'auto_refresh': False, + 'push_notifications': False, + 'dark_patterns_opt_in': False + } } - } - return render_template('dashboard.html', user_settings=user_settings, anonymous=True) + return render_template('dashboard.html', user_settings=user_settings, anonymous=True) + else: + # Redirect non-authenticated users to login + return redirect(url_for('login')) @app.route('/feed/') diff --git a/docker-compose.yml b/docker-compose.yml index 9c20ce1..44c21d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,7 @@ services: FLASK_ENV: production DEBUG: "False" SECRET_KEY: ${SECRET_KEY:-change-this-secret-key-in-production} + ALLOW_ANONYMOUS_ACCESS: ${ALLOW_ANONYMOUS_ACCESS:-true} # Auth0 configuration (optional) AUTH0_DOMAIN: ${AUTH0_DOMAIN:-} diff --git a/templates/dashboard.html b/templates/dashboard.html index c13b1e8..4080cfc 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -30,13 +30,21 @@
⚙️ Settings diff --git a/templates/post_detail.html b/templates/post_detail.html index 72ebb4e..c83bb02 100644 --- a/templates/post_detail.html +++ b/templates/post_detail.html @@ -654,6 +654,10 @@ function sharePost() { } function savePost() { + // TODO: Implement save post functionality + // User can save posts to their profile for later viewing + // This needs database backend integration with user_saved_posts table + // Same implementation needed as dashboard.html savePost function alert('Save functionality coming soon!'); }