Skip to content

Commit 4176b91

Browse files
committed
Add no-cache headers for auth pages and improve error messages
- Add nginx no-cache location for auth pages (verify-email, reset-password, forgot-password, login, register, accept-invitation, verify-new-email) - Improve API error messages to be more descriptive and actionable: - Verification: clearer expired/invalid/already-used messages - Password reset: better expired/invalid/social-login messages - Login: more helpful email verification and credentials messages
1 parent 3291682 commit 4176b91

2 files changed

Lines changed: 43 additions & 13 deletions

File tree

cloud/deploy/nginx/nginx.conf.template

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ http {
158158
# Blazor WASM Application (/app/*)
159159
# =====================================================
160160

161+
# Auth pages - no cache (ensure fresh content after deployments)
162+
location ~ ^/app/(verify-email|reset-password|forgot-password|login|register|accept-invitation|verify-new-email) {
163+
proxy_pass http://web/;
164+
proxy_http_version 1.1;
165+
proxy_set_header Host $host;
166+
proxy_set_header X-Real-IP $remote_addr;
167+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
168+
proxy_set_header X-Forwarded-Proto $scheme;
169+
170+
# Prevent caching
171+
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" always;
172+
add_header Pragma "no-cache" always;
173+
expires -1;
174+
}
175+
161176
location /app/_framework/ {
162177
proxy_pass http://web/_framework/;
163178
proxy_http_version 1.1;
@@ -285,6 +300,21 @@ http {
285300
# Blazor WASM Application (/app/*)
286301
# =====================================================
287302

303+
# Auth pages - no cache (ensure fresh content after deployments)
304+
location ~ ^/app/(verify-email|reset-password|forgot-password|login|register|accept-invitation|verify-new-email) {
305+
proxy_pass http://web/;
306+
proxy_http_version 1.1;
307+
proxy_set_header Host $host;
308+
proxy_set_header X-Real-IP $remote_addr;
309+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
310+
proxy_set_header X-Forwarded-Proto $scheme;
311+
312+
# Prevent caching
313+
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" always;
314+
add_header Pragma "no-cache" always;
315+
expires -1;
316+
}
317+
288318
location /app/_framework/ {
289319
proxy_pass http://web/_framework/;
290320
proxy_http_version 1.1;

cloud/src/LrmCloud.Api/Services/AuthService.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,28 @@ await _mailService.TrySendEmailAsync(_logger,
150150

151151
if (user == null)
152152
{
153-
return (false, "Invalid verification link");
153+
return (false, "This verification link is invalid. Please check the link or request a new one.");
154154
}
155155

156156
if (user.EmailVerified)
157157
{
158-
return (false, "Email already verified");
158+
return (false, "Your email address has already been verified. You can log in now.");
159159
}
160160

161161
if (user.EmailVerificationExpiresAt == null || user.EmailVerificationExpiresAt < DateTime.UtcNow)
162162
{
163-
return (false, "Verification link expired");
163+
return (false, "This verification link has expired. Please register again to receive a new link.");
164164
}
165165

166166
if (string.IsNullOrEmpty(user.EmailVerificationTokenHash))
167167
{
168-
return (false, "Invalid verification token");
168+
return (false, "This verification link is invalid or has already been used.");
169169
}
170170

171171
// Verify token by hashing and comparing
172172
if (!BCrypt.Net.BCrypt.Verify(token, user.EmailVerificationTokenHash))
173173
{
174-
return (false, "Invalid verification token");
174+
return (false, "This verification link is invalid or has already been used.");
175175
}
176176

177177
// Mark as verified
@@ -263,25 +263,25 @@ await _mailService.TrySendEmailAsync(_logger,
263263
.FirstOrDefaultAsync(u => u.Email == request.Email.ToLowerInvariant());
264264

265265
if (user == null)
266-
return (false, "Invalid password reset link");
266+
return (false, "This password reset link is invalid. Please request a new one.");
267267

268268
if (user.AuthType != "email")
269-
return (false, "Password reset is only available for email accounts");
269+
return (false, "Password reset is only available for email/password accounts. You signed up with a social login.");
270270

271271
if (string.IsNullOrEmpty(user.PasswordResetTokenHash))
272272
{
273-
return (false, "No password reset requested");
273+
return (false, "No password reset was requested for this account. Please request a new reset link.");
274274
}
275275

276276
if (user.PasswordResetExpires == null || user.PasswordResetExpires < DateTime.UtcNow)
277277
{
278-
return (false, "Password reset link expired");
278+
return (false, "This password reset link has expired. Please request a new one.");
279279
}
280280

281281
// Verify token by hashing and comparing
282282
if (!BCrypt.Net.BCrypt.Verify(request.Token, user.PasswordResetTokenHash))
283283
{
284-
return (false, "Invalid password reset token");
284+
return (false, "This password reset link is invalid or has already been used.");
285285
}
286286

287287
// Hash new password
@@ -348,7 +348,7 @@ await _mailService.TrySendEmailAsync(_logger,
348348
// Validate user exists and uses email auth
349349
if (user == null || user.AuthType != "email")
350350
{
351-
return (false, null, "Invalid email or password");
351+
return (false, null, "The email or password you entered is incorrect.");
352352
}
353353

354354
// Verify password
@@ -374,13 +374,13 @@ await _mailService.TrySendEmailAsync(_logger,
374374
_logger.LogWarning("Failed login attempt for user: {Email} (attempt {Count}/{Max})",
375375
user.Email, user.FailedLoginAttempts, _config.Auth.MaxFailedLoginAttempts);
376376

377-
return (false, null, "Invalid email or password");
377+
return (false, null, "The email or password you entered is incorrect.");
378378
}
379379

380380
// Check if email is verified
381381
if (!user.EmailVerified)
382382
{
383-
return (false, null, "Please verify your email address before logging in");
383+
return (false, null, "Please verify your email address before logging in. Check your inbox for the verification link.");
384384
}
385385

386386
// Success - reset failed attempts and update last login

0 commit comments

Comments
 (0)