Add /api/auth/status endpoint for JavaScript compatibility

This commit is contained in:
Lukas Pupka-Lipinski 2025-10-05 23:42:59 +02:00
parent 2c8c9a788c
commit e3b752a2a7
2 changed files with 122 additions and 100 deletions

View File

@ -343,6 +343,31 @@ async def logout(current_user: Dict = Depends(get_current_user)) -> Dict[str, An
"message": "Logged out successfully. Please remove the token from client storage."
}
@app.get("/api/auth/status", response_model=Dict[str, Any], tags=["Authentication"])
async def auth_status(request: Request) -> Dict[str, Any]:
"""
Check authentication status and configuration.
This endpoint checks if master password is configured and if user is authenticated.
"""
has_master_password = bool(settings.master_password_hash or settings.master_password)
# Check if user has valid token
authenticated = False
try:
auth_header = request.headers.get("authorization")
if auth_header and auth_header.startswith("Bearer "):
token = auth_header.split(" ")[1]
payload = verify_jwt_token(token)
authenticated = payload is not None
except Exception:
authenticated = False
return {
"has_master_password": has_master_password,
"authenticated": authenticated
}
# Health check endpoint
@app.get("/health", response_model=HealthResponse, tags=["System"])
async def health_check() -> HealthResponse:

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -127,10 +128,21 @@
transition: background-color 0.2s ease;
}
.strength-bar.active.weak { background: var(--color-error); }
.strength-bar.active.fair { background: var(--color-warning); }
.strength-bar.active.good { background: var(--color-info); }
.strength-bar.active.strong { background: var(--color-success); }
.strength-bar.active.weak {
background: var(--color-error);
}
.strength-bar.active.fair {
background: var(--color-warning);
}
.strength-bar.active.good {
background: var(--color-info);
}
.strength-bar.active.strong {
background: var(--color-success);
}
.strength-text {
font-size: 0.8rem;
@ -253,6 +265,7 @@
}
</style>
</head>
<body>
<div class="setup-container">
<button class="theme-toggle" id="theme-toggle" title="Toggle theme">
@ -271,14 +284,8 @@
<form class="setup-form" id="setup-form">
<div class="form-group">
<label for="directory" class="form-label">Anime Directory</label>
<input
type="text"
id="directory"
name="directory"
class="form-input"
placeholder="C:\Anime"
value="{{ current_directory }}"
required>
<input type="text" id="directory" name="directory" class="form-input" placeholder="C:\Anime"
value="{{ current_directory }}" required>
<div class="form-help">
The directory where your anime series are stored. This can be changed later in settings.
</div>
@ -287,14 +294,8 @@
<div class="form-group">
<label for="password" class="form-label">Master Password</label>
<div class="password-input-group">
<input
type="password"
id="password"
name="password"
class="form-input password-input"
placeholder="Create a strong password"
required
minlength="8">
<input type="password" id="password" name="password" class="form-input password-input"
placeholder="Create a strong password" required minlength="8">
<button type="button" class="password-toggle" id="password-toggle" tabindex="-1">
<i class="fas fa-eye"></i>
</button>
@ -311,13 +312,8 @@
<div class="form-group">
<label for="confirm-password" class="form-label">Confirm Password</label>
<div class="password-input-group">
<input
type="password"
id="confirm-password"
name="confirm-password"
class="form-input password-input"
placeholder="Confirm your password"
required
<input type="password" id="confirm-password" name="confirm-password"
class="form-input password-input" placeholder="Confirm your password" required
minlength="8">
<button type="button" class="password-toggle" id="confirm-password-toggle" tabindex="-1">
<i class="fas fa-eye"></i>
@ -560,4 +556,5 @@
});
</script>
</body>
</html>