commit faed7f5e6118613732e1c1c6aa6ef9a800ac4446
Author: plundrichov <monika.plundrichova@yoso.fi>
Date:   Wed Jul 8 15:42:21 2020 +0200

    re #58 conected to correct server, added config.json, added credentials in api.js and relocated errors 401, 403 to home page instead of throwing alert, edited login, edit link navbar logo

diff --git a/client/public/config.json b/client/public/config.json
new file mode 100644
index 0000000..8ef46dc
--- /dev/null
+++ b/client/public/config.json
@@ -0,0 +1,4 @@
+{
+    "baseUrl": "https://ymanager-api-yosoinfra.apps.oc.yoso.fi/api",
+    "redirectUrl": "http://localhost:3000/"
+}
\ No newline at end of file
diff --git a/client/src/App.css b/client/src/App.css
index d642dd0..3b8eb64 100644
--- a/client/src/App.css
+++ b/client/src/App.css
@@ -56,6 +56,12 @@
     margin-left: 85px;
 }
 
+.link-nav {
+    text-decoration: none;
+    color: #fff; 
+    cursor: pointer;  
+}
+
 .top-nav h4 {
     color: white;
 }
@@ -292,6 +298,13 @@ input {
     color: white;
     font-size: 90px;
 }
+.login-container a {
+  
+    text-decoration: none;
+    color: #fff; 
+    cursor: pointer;  
+
+}
 /* ------------- SETTING -------------------*/
 
 .setting-container {
diff --git a/client/src/App.js b/client/src/App.js
index 412b0d1..4487149 100644
--- a/client/src/App.js
+++ b/client/src/App.js
@@ -15,6 +15,8 @@ import * as api_fetch from './api'
 function App() {
 
   useEffect(() => {
+    if (window.location.pathname === '/login') return;
+
     api_fetch.getCurrentProfile().then(currentProfile => {
       setUserName(currentProfile);
     }).catch(reason => {
diff --git a/client/src/Login.js b/client/src/Login.js
index 40c48db..86c943a 100644
--- a/client/src/Login.js
+++ b/client/src/Login.js
@@ -3,10 +3,13 @@ import './App.css';
 
 
 function Login() {
-
+console.log(window.config)
   return (
     <div className="login-container column">
-      <h1>log in</h1>
+     
+    <a href={window.config.baseUrl + '/login/google?target=' + window.config.redirectUrl}><h1>log in</h1></a>
+     
+
     </div>
   )
 }
diff --git a/client/src/Nav.js b/client/src/Nav.js
index 030d883..84fe666 100644
--- a/client/src/Nav.js
+++ b/client/src/Nav.js
@@ -6,7 +6,7 @@ function Nav(props) {
 
   return (
     <nav className="top-nav">
-      <h3>YOSO</h3>
+      <a className="link-nav" href="http://localhost:3000/"><h3>YOSO</h3></a>
       <div className="profile-comp">
       <img src="https://cataas.com/cat/says/hello%20world!" className="img-avatar" alt="cat"></img>
         <h5>{props.userName.name}</h5>
diff --git a/client/src/api.js b/client/src/api.js
index d1212ad..6ae27fa 100644
--- a/client/src/api.js
+++ b/client/src/api.js
@@ -1,6 +1,3 @@
-
-const http = 'http://devcz.yoso.fi:8090/ymanager';
-
 // ******************** GET DATA APP getCurrentProfile ********************
 
 export const getCurrentProfile = async () => {
@@ -9,11 +6,12 @@ export const getCurrentProfile = async () => {
 
   try {
     response = await fetch(
-      `${http}/users/current/profile`, {
+      `${window.config.baseUrl}/users/current/profile`, {
         headers: {
           Authorization: 1
-          
-        }
+
+        },
+        credentials: 'include'
       }
     );    
   } catch (e) {
@@ -34,7 +32,11 @@ export const getCurrentProfile = async () => {
   } else {
       switch (response.status) {
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
+          break;
+        case 403:
+          window.location.replace("http://localhost:3000/login")
+          break;
         case 500:
           throw new Error('Internal server error.')
         default:
@@ -50,11 +52,12 @@ export const getUserCalendar = async (userName, fromDate ) => {
 
   try {
     response = await fetch(
-      `${http}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
+      `${window.config.baseUrl}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
         headers: {
           'Accept': 'application/json',
           Authorization: 6
         },
+        credentials: 'include',
         method: 'GET',
       }
     );
@@ -82,9 +85,9 @@ export const getUserCalendar = async (userName, fromDate ) => {
         case 400:
           throw new Error('Bad request. Check query parameters.')
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
         case 403:
-          throw new Error('Not authorized.')
+          window.location.replace("http://localhost:3000/login")
         case 404:
           throw new Error('User with given ID does not exist.')
         case 500:
@@ -103,11 +106,12 @@ export const getAdminCalendar = async () => {
 
   try {
     response = await fetch(
-      `${http}/users/requests/vacation?status=ACCEPTED`, {
+      `${window.config.baseUrl}/users/requests/vacation?status=ACCEPTED`, {
         headers: {
           'Accept': 'application/json',
-          Authorization: 1
+          Authorization: 6
         },
+        credentials: 'include',
         method: 'GET',
       }
     );
@@ -132,9 +136,9 @@ export const getAdminCalendar = async () => {
         case 400:
           throw new Error('Bad request. Check query parameters.')
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
         case 403:
-          throw new Error('Not authorized.')
+          window.location.replace("http://localhost:3000/login")
         case 500:
           throw new Error('Internal server error.')
         default:
@@ -145,16 +149,17 @@ export const getAdminCalendar = async () => {
 
 // ******************** ADD EVENT to CALENDAR - EMPLOYEE ********************
 
-export async function addEventApi(dataAddEventEmployee) {
+export async function addEventApi(userName, dataAddEventEmployee) {
   let response;
 
   try {
   // send accepted request to server
-    response = await fetch(`${http}/user/calendar/create`, {
+    response = await fetch(`${window.config.baseUrl}/user/calendar/create`, {
       headers: {
         Authorization: 6,
         'Content-Type': 'application/json',
       },
+      credentials: 'include',
       method: 'POST',
   // object which is sent to server
   body: JSON.stringify(dataAddEventEmployee),
@@ -166,10 +171,11 @@ export async function addEventApi(dataAddEventEmployee) {
   if (response.ok) {
       
     response = await fetch(
-    `${http}/users/requests/vacation?status=PENDING`, {
+    `${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
       headers: {
         Authorization: 1
       },
+      credentials: 'include',
     });
     const data = await response.json();
       
@@ -193,9 +199,9 @@ export async function addEventApi(dataAddEventEmployee) {
         case 400:
           throw new Error('Bad request. Check request body.')
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
         case 403:
-          throw new Error('Not authorized.')
+          window.location.replace("http://localhost:3000/login")
         case 500:
           throw new Error('Internal server error.')
         default:
@@ -211,11 +217,12 @@ export async function addEventApiAdmin(dataAddEventAdmin) {
 
   try {
   // send accepted request to server
-    response = await fetch(`${http}/user/calendar/create`, {
+    response = await fetch(`${window.config.baseUrl}/user/calendar/create`, {
       headers: {
         Authorization: 1,
         'Content-Type': 'application/json',
     },
+    credentials: 'include',
       method: 'POST',
     // object which is sent to server
       body: JSON.stringify(dataAddEventAdmin),
@@ -229,9 +236,9 @@ export async function addEventApiAdmin(dataAddEventAdmin) {
       case 400:
         throw new Error('Bad request. Check request body.')
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 500:
         throw new Error('Internal server error.')
       default:
@@ -247,9 +254,11 @@ export const getUsersOverview = async () => {
 
   try {
   response = await fetch (
-    `${http}/users`, {
+    `${window.config.baseUrl}/users`, {
       headers: {
-        Authorization: 1          }
+        Authorization: 1          
+      },
+      credentials: 'include',
     }
   );
   } catch (e) {
@@ -275,9 +284,9 @@ export const getUsersOverview = async () => {
       case 400:
         throw new Error('Bad request. Check query parameters.')
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 500:
         throw new Error('Internal server error.')
       default:
@@ -293,11 +302,12 @@ export async function saveDataOverview(dataOverviewObject) {
 
   try {
     // send accepted request to server
-        response = await fetch(`${http}/user/settings`, {
+        response = await fetch(`${window.config.baseUrl}/user/settings`, {
           headers: {
             Authorization: 1,
             'Content-Type': 'application/json',
           },
+          credentials: 'include',
           method: 'PUT',
  
     // object which is sent to server
@@ -312,9 +322,9 @@ export async function saveDataOverview(dataOverviewObject) {
       case 400:
         throw new Error('Bad request. Check query parameters.')
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 500:
         throw new Error('Internal server error.')
       default:
@@ -329,12 +339,14 @@ export const getSettingData = async () =>  {
 
   try {
     response = await fetch(
-      `${http}/settings`, {
+      `${window.config.baseUrl}/settings`, {
         headers: {
           Authorization: 1
+        },
+        credentials: 'include',
+      }
+    );
 
-        }
-      });
   } catch (e) {
     throw 'Server is not available'
     }
@@ -360,11 +372,12 @@ export async function saveDataSetting(dataSettingObject) {
   let response;
 
   try {
-    response = await fetch(`${http}/settings`, {
+    response = await fetch(`${window.config.baseUrl}/settings`, {
       headers: {
         'Authorization': 1,
         'Content-Type': 'application/json'
       },
+      credentials: 'include',
       method: 'POST',
       body: JSON.stringify(dataSettingObject),
     });
@@ -375,9 +388,9 @@ export async function saveDataSetting(dataSettingObject) {
   if (!response.ok) {
     switch (response.status) {
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 500:
         throw new Error('Internal server error.')
       default:
@@ -388,15 +401,16 @@ export async function saveDataSetting(dataSettingObject) {
 
 // ****************** LOAD DATA to YOUR REQUESTS - EMPLOYEE ******************
 
-export async function loadYourRequests() {
+export async function loadYourRequests(userName) {
   let response;
   
   try {
     response = await fetch(
-      `${http}/user/6/calendar?from=2020/06/24&status=PENDING`, {
+      `${window.config.baseUrl}/user/${userName.id}/calendar?from=2020/06/24&status=PENDING`, {
         headers: {
           Authorization: 6
         },
+        credentials: 'include',
       }
     );
   } catch (e) {
@@ -411,9 +425,9 @@ export async function loadYourRequests() {
         case 400:
           throw new Error('Bad request. Check query parameters.')
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
         case 403:
-          throw new Error('Not authorized.')
+          window.location.replace("http://localhost:3000/login")
         case 500:
           throw new Error('Internal server error.')
         default:
@@ -428,10 +442,11 @@ export async function loadAdminRequests() {
 
   try {
     response = await fetch(
-      `${http}/users/requests/vacation?status=PENDING`, {
+      `${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
         headers: {
           Authorization: 1
-        }
+        },
+        credentials: 'include',
       },
     );
   } catch (e) {
@@ -446,9 +461,9 @@ export async function loadAdminRequests() {
         case 400:
           throw new Error('Bad request. Check query parameters.')
         case 401:
-          throw new Error('Not authenticated.')
+          window.location.replace("http://localhost:3000/login")
         case 403:
-          throw new Error('Not authorized.')
+          window.location.replace("http://localhost:3000/login")
         case 500:
           throw new Error('Internal server error.')
         default:
@@ -463,11 +478,12 @@ export async function sendAcceptedRequest(acceptedRequests) {
   let response;
 
   try {
-    response = await fetch(`${http}/user/requests?type=VACATION`, {
+    response = await fetch(`${window.config.baseUrl}/user/requests?type=VACATION`, {
       headers: {
         Authorization: 1,
         'Content-Type': 'application/json',
       },
+      credentials: 'include',
       method: 'PUT',
       body: JSON.stringify(acceptedRequests),
     });
@@ -480,9 +496,9 @@ export async function sendAcceptedRequest(acceptedRequests) {
       case 400:
         throw new Error('Bad request. Check query parameters and request body.')
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 404:
         throw new Error('Neither vacation nor authorization request with given ID exists.')
       case 500:
@@ -499,11 +515,12 @@ export async function sendRejectedRequest(rejectedRequest) {
   let response;
   
   try {
-    response = await fetch(`${http}/user/requests?type=VACATION`, {
+    response = await fetch(`${window.config.baseUrl}/user/requests?type=VACATION`, {
       headers: {
         Authorization: 1,
         'Content-Type': 'application/json',
       },
+      credentials: 'include',
       method: 'PUT',
       body: JSON.stringify(rejectedRequest),
     });
@@ -516,9 +533,9 @@ export async function sendRejectedRequest(rejectedRequest) {
       case 400:
         throw new Error('Bad request. Check query parameters and request body.')
       case 401:
-        throw new Error('Not authenticated.')
+        window.location.replace("http://localhost:3000/login")
       case 403:
-        throw new Error('Not authorized.')
+        window.location.replace("http://localhost:3000/login")
       case 404:
         throw new Error('Neither vacation nor authorization request with given ID exists.')
       case 500:
diff --git a/client/src/index.js b/client/src/index.js
index f5185c1..5c2c2a3 100644
--- a/client/src/index.js
+++ b/client/src/index.js
@@ -3,13 +3,22 @@ import ReactDOM from 'react-dom';
 import './index.css';
 import App from './App';
 import * as serviceWorker from './serviceWorker';
+import { render } from '@testing-library/react';
+
+fetch(
+  "config.json").then((response) => response.json()).then(config => {
+    window.config = config;
+    ReactDOM.render(
+      <React.StrictMode>
+        <App />
+      </React.StrictMode>,
+      document.getElementById('root')
+    );
+    
+  });
+
+
 
-ReactDOM.render(
-  <React.StrictMode>
-    <App />
-  </React.StrictMode>,
-  document.getElementById('root')
-);
 
 // If you want your app to work offline and load faster, you can change
 // unregister() to register() below. Note this comes with some pitfalls.
