From e8bd009a1dfcf0e4de45b16ad5ca281d6e43ae51 Mon Sep 17 00:00:00 2001 From: s85708 <s85708@bht-berlin.de> Date: Wed, 11 Jan 2023 08:57:33 +0100 Subject: [PATCH] delete not wroking --- my-app/src/actions/AuthenticationActions.js | 6 ++- my-app/src/actions/UserManagementActions.js | 57 ++++----------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/my-app/src/actions/AuthenticationActions.js b/my-app/src/actions/AuthenticationActions.js index 00786af..d6c2d10 100644 --- a/my-app/src/actions/AuthenticationActions.js +++ b/my-app/src/actions/AuthenticationActions.js @@ -94,13 +94,15 @@ function handleResponse(response) { const data = text && JSON.parse(text); var splittedToken - var token + var token var adminRights if (authorizationHeader) { - splittedToken = authorizationHeader.split(" ")[1]; token = authorizationHeader + splittedToken = authorizationHeader.split(" ")[1]; adminRights = JSON.parse(atob(splittedToken.split(".")[1])) console.log(adminRights) + console.log(token) + } if (!response.ok) { diff --git a/my-app/src/actions/UserManagementActions.js b/my-app/src/actions/UserManagementActions.js index 05bded9..d9b778e 100644 --- a/my-app/src/actions/UserManagementActions.js +++ b/my-app/src/actions/UserManagementActions.js @@ -71,23 +71,6 @@ export function getCreateNewUserErrorAction(error) { } -export function getDeleteUserSuccessAction(message) { - console.log("GetDeleteUserSuccessAction") - return { - type: DELETE_USER_SUCCESS, - message: message - } -} - -export function getDeleteUserErrorAction(error) { - console.log("GetDeleteUserErrorAction") - return { - type: DELETE_USER_ERROR, - error: error - } -} - - //Frontend Connections @@ -161,16 +144,16 @@ export function deleteUserWithUserID(userID, token) { return dispatch => { dispatch(getDeleteUserSuccessAction()); deleteUser(userID, token) - .then(successMessage => { - const action = getDeleteUserSuccessAction(successMessage); - dispatch(action); - }, - error => { - dispatch(getDeleteUserErrorAction(error)); - } - ).catch(error => { + .then(successMessage => { + const action = getDeleteUserSuccessAction(successMessage); + dispatch(action); + }, + error => { + dispatch(getDeleteUserErrorAction(error)); + } + ).catch(error => { dispatch(getDeleteUserErrorAction(error)); - }) + }) } } @@ -222,26 +205,6 @@ export function createNewUser(userData, token) { }) } -export function deleteUser(userID, token) { - - const requestOptions = { - method: 'DELETE', - headers: { - 'Authorization': token - } - } - - return fetch('https://localhost/api/users/' + userID, requestOptions) - .then(response => { - return response.json().then(body => { - if (response.status === 204) { - console.log(body) - return body - } - }) - }) -} - export function deleteUser(userID, token) { console.log("delete user") @@ -259,7 +222,7 @@ export function deleteUser(userID, token) { return response.json().then(() => { if (response.status === 204) { console.log("user successfully deleted") - return + return } }) }) -- GitLab