Fix Auth0 500 error when not configured (Issue #5)
- Add check for AUTH0 credentials before attempting login - Show friendly error message if Auth0 not configured - Hide Auth0 button on login page when not configured - Add try/catch for auth0.authorize_redirect() failures Fixes #5
This commit is contained in:
17
app.py
17
app.py
@@ -704,6 +704,9 @@ def login():
|
|||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
# Check if Auth0 is configured
|
||||||
|
auth0_configured = bool(app.config.get('AUTH0_DOMAIN') and app.config.get('AUTH0_CLIENT_ID'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form.get('username')
|
username = request.form.get('username')
|
||||||
password = request.form.get('password')
|
password = request.form.get('password')
|
||||||
@@ -711,7 +714,7 @@ def login():
|
|||||||
|
|
||||||
if not user_service:
|
if not user_service:
|
||||||
flash('User service not available', 'error')
|
flash('User service not available', 'error')
|
||||||
return render_template('login.html')
|
return render_template('login.html', auth0_configured=auth0_configured)
|
||||||
|
|
||||||
user = user_service.authenticate(username, password)
|
user = user_service.authenticate(username, password)
|
||||||
|
|
||||||
@@ -725,7 +728,7 @@ def login():
|
|||||||
else:
|
else:
|
||||||
flash('Invalid username or password', 'error')
|
flash('Invalid username or password', 'error')
|
||||||
|
|
||||||
return render_template('login.html')
|
return render_template('login.html', auth0_configured=auth0_configured)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/password-reset-request', methods=['GET', 'POST'])
|
@app.route('/password-reset-request', methods=['GET', 'POST'])
|
||||||
@@ -804,8 +807,18 @@ def password_reset(token):
|
|||||||
@app.route('/auth0/login')
|
@app.route('/auth0/login')
|
||||||
def auth0_login():
|
def auth0_login():
|
||||||
"""Redirect to Auth0 for authentication"""
|
"""Redirect to Auth0 for authentication"""
|
||||||
|
# Check if Auth0 is configured
|
||||||
|
if not app.config.get('AUTH0_DOMAIN') or not app.config.get('AUTH0_CLIENT_ID'):
|
||||||
|
flash('Auth0 authentication is not configured. Please use email/password login or contact the administrator.', 'error')
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
try:
|
||||||
redirect_uri = url_for('auth0_callback', _external=True)
|
redirect_uri = url_for('auth0_callback', _external=True)
|
||||||
return auth0.authorize_redirect(redirect_uri)
|
return auth0.authorize_redirect(redirect_uri)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Auth0 login error: {e}")
|
||||||
|
flash('Auth0 authentication failed. Please use email/password login.', 'error')
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/auth0/callback')
|
@app.route('/auth0/callback')
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
<span>or</span>
|
<span>or</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if auth0_configured %}
|
||||||
<div class="social-auth-buttons">
|
<div class="social-auth-buttons">
|
||||||
<a href="{{ url_for('auth0_login') }}" class="social-btn auth0-btn">
|
<a href="{{ url_for('auth0_login') }}" class="social-btn auth0-btn">
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
Continue with Auth0
|
Continue with Auth0
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="auth-footer">
|
<div class="auth-footer">
|
||||||
<p>Don't have an account? <a href="{{ url_for('signup') }}">Sign up</a></p>
|
<p>Don't have an account? <a href="{{ url_for('signup') }}">Sign up</a></p>
|
||||||
|
|||||||
Reference in New Issue
Block a user