Remove password fields from users page
This commit is contained in:
@@ -25,8 +25,6 @@ export default function UsersPage() {
|
||||
const [users, setUsers] = useState<AdminUser[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [passwordInputs, setPasswordInputs] = useState<Record<string, string>>({})
|
||||
const [passwordStatus, setPasswordStatus] = useState<Record<string, string>>({})
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
@@ -105,42 +103,6 @@ export default function UsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const updateUserPassword = async (username: string) => {
|
||||
const newPassword = passwordInputs[username] || ''
|
||||
if (!newPassword || newPassword.length < 8) {
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Password must be at least 8 characters.',
|
||||
}))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(
|
||||
`${baseUrl}/admin/users/${encodeURIComponent(username)}/password`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password: newPassword }),
|
||||
}
|
||||
)
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Update failed')
|
||||
}
|
||||
setPasswordInputs((current) => ({ ...current, [username]: '' }))
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Password updated.',
|
||||
}))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setPasswordStatus((current) => ({
|
||||
...current,
|
||||
[username]: 'Could not update password.',
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
@@ -197,27 +159,6 @@ export default function UsersPage() {
|
||||
{user.isBlocked ? 'Allow access' : 'Block access'}
|
||||
</button>
|
||||
</div>
|
||||
{user.authProvider === 'local' && (
|
||||
<div className="user-actions">
|
||||
<input
|
||||
type="password"
|
||||
placeholder="New password (min 8 chars)"
|
||||
value={passwordInputs[user.username] || ''}
|
||||
onChange={(event) =>
|
||||
setPasswordInputs((current) => ({
|
||||
...current,
|
||||
[user.username]: event.target.value,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<button type="button" onClick={() => updateUserPassword(user.username)}>
|
||||
Set password
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{passwordStatus[user.username] && (
|
||||
<div className="meta">{passwordStatus[user.username]}</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user