Fix sonar issues
[clamp.git] / ui-react / src / api / UserService.js
index be21e69..8da6e3a 100644 (file)
@@ -26,7 +26,7 @@ export default class UserService {
        static login() {
                return fetch('/restservices/clds/v1/user/getUser', {
                                method: 'GET',
-                               credentials: 'same-origin',
+                               credentials: 'same-origin'
                        })
                .then(function (response) {
                        console.debug("getUser response received, status code:", response.status);
@@ -47,11 +47,36 @@ export default class UserService {
                        return UserService.notLoggedUserName;
                });
        }
+       
+       static logout() {
+               return fetch('/restservices/clds/v1/user/logout', {
+                       method: 'POST',
+                       credentials: 'same-origin'
+               })
+               .then(function (response) {
+                       console.debug("logout response received, status code:", response.status);
+                       if (response.ok) {
+                               return response.text();
+                       } else {
+                               console.error("logout response is nok");
+                               return UserService.notLoggedUserName;
+                       }
+               })
+               .then(function (data) {
+                       console.info ("User disconnected:",data)
+                       return data;
+               })
+               .catch(function(error) {
+                       console.warn("logout error received, user set to: ",UserService.notLoggedUserName);
+                       console.error("logout error:",error);
+                       return UserService.notLoggedUserName;
+               });
+       }
 
        static getUserInfo() {
                return fetch('/restservices/clds/v1/clds/cldsInfo', {
                                method: 'GET',
-                               credentials: 'same-origin',
+                               credentials: 'same-origin'
                        })
                .then(function (response) {
                        console.debug("getUserInfo response received, status code:", response.status);