diff --git a/app.jsx b/app.jsx index b011fba..d6799f0 100644 --- a/app.jsx +++ b/app.jsx @@ -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 { - 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); }} />; diff --git a/backend/main.py b/backend/main.py index 58ce2a4..d211daa 100644 --- a/backend/main.py +++ b/backend/main.py @@ -21,7 +21,12 @@ app.add_middleware( @app.post("/token", response_model=schemas.Token) async def login_for_access_token(form_data: schemas.UserLogin, db: Session = Depends(get_db)): - user = db.query(models.User).filter(models.User.id == form_data.id).first() + # Search by ID or Name + user = db.query(models.User).filter( + (models.User.id == form_data.id) | + (models.User.name == form_data.id) + ).first() + if not user or not auth.verify_password(form_data.password, user.password_hash): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, @@ -32,7 +37,7 @@ async def login_for_access_token(form_data: schemas.UserLogin, db: Session = Dep return {"access_token": access_token, "token_type": "bearer"} @app.get("/users", response_model=List[schemas.User]) -def read_users(db: Session = Depends(get_db), current_user: models.User = Depends(auth.get_current_user)): +def read_users(db: Session = Depends(get_db)): return db.query(models.User).all() @app.post("/users", response_model=schemas.User) @@ -169,7 +174,7 @@ def restore_task(task_id: str, db: Session = Depends(get_db), current_user: mode db.refresh(db_task) return db_task @app.get("/workspace", response_model=schemas.Workspace) -def read_workspace(db: Session = Depends(get_db), current_user: models.User = Depends(auth.get_current_user)): +def read_workspace(db: Session = Depends(get_db)): ws = db.query(models.Workspace).first() if not ws: ws = models.Workspace(id="default", name="murchison-auto", timezone="Pacific/Auckland") diff --git a/dashy.db b/dashy.db index f3bda5a..f071693 100644 Binary files a/dashy.db and b/dashy.db differ diff --git a/screens.jsx b/screens.jsx index 4a55f1d..60700f2 100644 --- a/screens.jsx +++ b/screens.jsx @@ -1,20 +1,19 @@ // Screens for Dashy function LoginScreen({ onLogin, dbUsers = [], workspace }) { - const [pickedId, setPickedId] = React.useState('rod'); + const [username, setUsername] = React.useState(''); const [password, setPassword] = React.useState(''); const [error, setError] = React.useState(''); const [busy, setBusy] = React.useState(false); - React.useEffect(() => { setPassword(''); setError(''); }, [pickedId]); - const submit = async () => { + if (!username) { setError('Enter your username'); return; } if (!password) { setError('Enter your password'); return; } setError(''); setBusy(true); try { - await onLogin(pickedId, password); + await onLogin(username, password); } catch (e) { - setError('Incorrect password'); + setError('Incorrect username or password'); } finally { setBusy(false); } @@ -27,43 +26,39 @@ function LoginScreen({ onLogin, dbUsers = [], workspace }) { Dashy -

Pick up where you left off.

-

Sign in to your team workspace · {workspace ? workspace.name : 'loading…'}

+

Sign in to Dashy

+

Enter your details to access the {workspace ? workspace.name : 'loading…'} workspace

-
- {dbUsers.map(u => ( - - ))} +
+ + +
- + {error &&
{error}
} - {error &&
{error}
} - -