Changed login screen to ask for username and password instead of displaying staff name

This commit is contained in:
NPS Agent
2026-05-12 11:21:09 +09:30
parent 7545d1da47
commit 84592b8b3b
4 changed files with 63 additions and 46 deletions
+22 -5
View File
@@ -14,17 +14,28 @@ function useApiData(authed) {
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
if (!authed) return;
let mounted = true;
const load = async () => {
try {
if (!authed) {
// Fetch only public data (workspace info and user list for login)
const [users, workspace] = await Promise.all([
api.getUsers().catch(() => []),
api.getWorkspace().catch(() => null)
]);
if (mounted) {
setData(prev => ({ ...prev, users, workspace }));
setLoading(false);
}
return;
}
const [tasks, users, audit, workspace, deletedTasks] = await Promise.all([
api.getTasks(),
api.getUsers(),
api.getAudit(),
api.getWorkspace(),
api.getDeletedTasks().catch(() => []) // Catch if not admin or error
api.getDeletedTasks().catch(() => [])
]);
if (mounted) {
setData({ tasks, users, audit, workspace, deletedTasks });
@@ -109,8 +120,14 @@ function App() {
if (!authed) {
return <LoginScreen dbUsers={dbUsers} workspace={workspace} onLogin={async (id, pwd) => {
await api.login(id, pwd);
setMeId(id);
const data = await api.login(id, pwd);
// Extract actual User ID from token payload
try {
const payload = JSON.parse(atob(data.access_token.split('.')[1]));
setMeId(payload.sub);
} catch(e) {
setMeId(id);
}
setAuthed(true);
api.addAudit({ actor: id, action: 'login', summary: 'Signed in' }).catch(console.error);
}} />;