From 45a31d1c052bae03f1502a1cc9758d4f6a831b7f Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Thu, 12 Nov 2020 16:05:06 +0100 Subject: [PATCH] Endpoints only retrieve / modify objects related to the active user. --- .../components/windows/login/LoginWindow.tsx | 21 ++++++++ server/app.ts | 2 +- server/endpoints/AlbumDetails.ts | 4 +- server/endpoints/ArtistDetails.ts | 3 ++ server/endpoints/CreateAlbum.ts | 6 ++- server/endpoints/CreateArtist.ts | 7 +-- server/endpoints/CreateSong.ts | 7 ++- server/endpoints/CreateTag.ts | 7 ++- server/endpoints/DeleteTag.ts | 14 ++--- server/endpoints/MergeTag.ts | 7 ++- server/endpoints/ModifyAlbum.ts | 5 +- server/endpoints/ModifyArtist.ts | 6 ++- server/endpoints/ModifySong.ts | 5 +- server/endpoints/ModifyTag.ts | 6 ++- server/endpoints/Query.ts | 25 ++++++--- server/endpoints/SongDetails.ts | 3 ++ server/endpoints/TagDetails.ts | 3 ++ server/migrations/20201110170100_add_users.ts | 54 +++++++++++++++++++ 18 files changed, 157 insertions(+), 28 deletions(-) diff --git a/client/src/components/windows/login/LoginWindow.tsx b/client/src/components/windows/login/LoginWindow.tsx index 134248a..fe9e216 100644 --- a/client/src/components/windows/login/LoginWindow.tsx +++ b/client/src/components/windows/login/LoginWindow.tsx @@ -3,14 +3,23 @@ import { WindowState } from "../Windows"; import { Box, Paper, Typography, TextField, Button } from "@material-ui/core"; import { useHistory, useLocation } from 'react-router'; import { useAuth, Auth } from '../../../lib/useAuth'; +import Alert from '@material-ui/lab/Alert'; + +export enum LoginStatus { + NoneSubmitted = 0, + Unsuccessful, + // Note: no "successful" status because that would lead to a redirect. +} export interface LoginWindowState extends WindowState { email: string, password: string, + status: LoginStatus, } export enum LoginWindowStateActions { SetEmail = "SetEmail", SetPassword = "SetPassword", + SetStatus = "SetStatus", } export function LoginWindowReducer(state: LoginWindowState, action: any) { switch (action.type) { @@ -18,6 +27,8 @@ export function LoginWindowReducer(state: LoginWindowState, action: any) { return { ...state, email: action.value } case LoginWindowStateActions.SetPassword: return { ...state, password: action.value } + case LoginWindowStateActions.SetStatus: + return { ...state, status: action.value } default: throw new Error("Unimplemented LoginWindow state update.") } @@ -27,6 +38,7 @@ export default function LoginWindow(props: {}) { const [state, dispatch] = useReducer(LoginWindowReducer, { email: "", password: "", + status: LoginStatus.NoneSubmitted, }); return @@ -46,6 +58,11 @@ export function LoginWindowControlled(props: { auth.signin(props.state.email, props.state.password) .then(() => { history.replace(from); + }).catch((e: any) => { + props.dispatch({ + type: LoginWindowStateActions.SetStatus, + value: LoginStatus.Unsuccessful, + }) }) } @@ -86,6 +103,10 @@ export function LoginWindowControlled(props: { value: e.target.value })} /> + {props.state.status === LoginStatus.Unsuccessful && + Login failed - Please check your credentials. + + }