-
+
{!isKanban &&
}
diff --git a/jam-ui/src/components/navbar/JKNotificationDropdown.js b/jam-ui/src/components/navbar/JKNotificationDropdown.js
index 05f815ce3..e2f4ba3ed 100644
--- a/jam-ui/src/components/navbar/JKNotificationDropdown.js
+++ b/jam-ui/src/components/navbar/JKNotificationDropdown.js
@@ -11,7 +11,7 @@ import Notification from '../notification/JKNotification';
import { fetchNotifications } from '../../store/features/notificationSlice';
import { useDispatch, useSelector } from 'react-redux';
-import { useAuth } from '../../context/AuthContext';
+import { useAuth } from '../../context/UserAuth';
const JKNotificationDropdown = () => {
const { currentUser } = useAuth();
diff --git a/jam-ui/src/components/navbar/JKProfileDropdown.js b/jam-ui/src/components/navbar/JKProfileDropdown.js
index 338883d67..d31ee0c8e 100644
--- a/jam-ui/src/components/navbar/JKProfileDropdown.js
+++ b/jam-ui/src/components/navbar/JKProfileDropdown.js
@@ -1,24 +1,24 @@
//import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useState } from 'react';
import { DropdownItem, DropdownMenu, DropdownToggle, Dropdown } from 'reactstrap';
-import { useAuth } from '../../context/AuthContext';
+import { useAuth } from '../../context/UserAuth';
import JKProfileAvatar from '../profile/JKProfileAvatar';
import { useCookies } from 'react-cookie';
const ProfileDropdown = () => {
const [dropdownOpen, setDropdownOpen] = useState(false);
const toggle = () => setDropdownOpen(prevState => !prevState);
- const { currentUser, setCurrentUser } = useAuth();
+ const { currentUser, setCurrentUser, logout } = useAuth();
const [cookies, setCookie, removeCookie] = useCookies(['remember_token']);
- const handleLogout = event => {
+ const handleLogout = async (event) => {
event.preventDefault();
removeCookie('remember_token', {
domain: `.${process.env.REACT_APP_ORIGIN}`
});
setCurrentUser(null);
- window.location.reload(false);
+ logout()
};
return (
diff --git a/jam-ui/src/components/page/JKPerson.js b/jam-ui/src/components/page/JKPerson.js
index 476a5baac..59d98dbcf 100644
--- a/jam-ui/src/components/page/JKPerson.js
+++ b/jam-ui/src/components/page/JKPerson.js
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Row, Col } from 'reactstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { useAuth } from '../../context/AuthContext';
+import { useAuth } from '../../context/UserAuth';
import { truncate } from '../../helpers/utils';
import { fetchPerson } from '../../store/features/peopleSlice'
import { useDispatch, useSelector } from 'react-redux'
diff --git a/jam-ui/src/components/profile/JKMessageModal.js b/jam-ui/src/components/profile/JKMessageModal.js
index ff26540c1..8f955d9c7 100644
--- a/jam-ui/src/components/profile/JKMessageModal.js
+++ b/jam-ui/src/components/profile/JKMessageModal.js
@@ -3,7 +3,7 @@ import { Modal, ModalHeader, ModalBody, Row, Col, Button, ModalFooter } from 're
import { Scrollbar } from 'react-scrollbars-custom';
import TimeAgo from '../common/JKTimeAgo'
import JKProfileAvatar from './JKProfileAvatar';
-import { useAuth } from '../../context/AuthContext';
+import { useAuth } from '../../context/UserAuth';
import { useDispatch, useSelector } from 'react-redux';
import { fetchMessagesByReceiverId, postNewMessage } from '../../store/features/textMessagesSlice';
import { isIterableArray } from '../../helpers/utils';
diff --git a/jam-ui/src/components/profile/JKProfileSidePanel.js b/jam-ui/src/components/profile/JKProfileSidePanel.js
index a1da4dca8..a50dbb110 100644
--- a/jam-ui/src/components/profile/JKProfileSidePanel.js
+++ b/jam-ui/src/components/profile/JKProfileSidePanel.js
@@ -7,7 +7,7 @@ import moment from 'moment';
import { Modal, ModalBody, ModalHeader } from 'reactstrap';
import ScrollBarCustom from '../common/ScrollBarCustom';
-import { useAuth } from '../../context/AuthContext';
+import { useAuth } from '../../context/UserAuth';
import { useTranslation } from "react-i18next";
import JKProfileAvatar from './JKProfileAvatar';
diff --git a/jam-ui/src/context/UserAuth.js b/jam-ui/src/context/UserAuth.js
new file mode 100644
index 000000000..76feedc4d
--- /dev/null
+++ b/jam-ui/src/context/UserAuth.js
@@ -0,0 +1,63 @@
+import React, { useState, useEffect, createContext, useContext } from 'react';
+import PropTypes from 'prop-types';
+import { checkIsAuthenticated, authSignUp, authLogin, authLogout } from '../services/auth'
+
+export const UserAuthContext = createContext({});
+
+export const useAuth = () => useContext(UserAuthContext)
+
+export default function UserAuth({ children, path }) {
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
+ const [currentUser, setCurrentUser] = useState(null)
+ const [isLoading, setIsLoading] = useState(true);
+
+ useEffect(() => {
+ console.log('checking auth........', path);
+ checkAuth();
+ }, [path]);
+
+ const checkAuth = () =>
+ checkIsAuthenticated()
+ .then((user) => {
+ setIsAuthenticated(true)
+ setCurrentUser(user)
+ window.currentUser = user;
+ })
+ .catch(() => {
+ setIsAuthenticated(false)
+ setCurrentUser(null)
+ window.currentUser = null;
+ })
+ .then(() => setIsLoading(false));
+
+ const login = credentials =>
+ authLogin(credentials)
+ .then(setIsAuthenticated(true))
+ .catch(error => {
+ console.log(error);
+ setIsAuthenticated(false);
+ });
+
+ const logout = () => {
+ authLogout()
+ setIsAuthenticated(false);
+ };
+
+ const signUp = credentials =>
+ authSignUp(credentials)
+ .then(setIsAuthenticated(true))
+ .catch(error => {
+ console.log(error);
+ setIsAuthenticated(false);
+ });
+
+ return (
+
+ {children}
+
+ );
+}
+
+// UserAuth.propTypes = {
+// children: PropTypes.oneOfType([PropTypes.func, PropTypes.array])
+// };
diff --git a/jam-ui/src/helpers/apiFetch.js b/jam-ui/src/helpers/apiFetch.js
index b405f6b82..611501524 100644
--- a/jam-ui/src/helpers/apiFetch.js
+++ b/jam-ui/src/helpers/apiFetch.js
@@ -32,7 +32,6 @@ function secureFetch(path, options) {
switch (response.status) {
case 403:
console.log('apiFetch Authentication error');
- // window.location.href = `${process.env.REACT_APP_LEGACY_BASE_URL}/signin`
break;
case 404:
console.log('apiFetch Object not found');
diff --git a/jam-ui/src/helpers/privateRoute.js b/jam-ui/src/helpers/privateRoute.js
new file mode 100644
index 000000000..4a329340a
--- /dev/null
+++ b/jam-ui/src/helpers/privateRoute.js
@@ -0,0 +1,33 @@
+import React, { useContext } from 'react';
+import { Route, Redirect } from 'react-router-dom';
+import PropTypes from 'prop-types';
+import { UserAuthContext } from '../context/UserAuth';
+//import Loading from '../../views/Loading/Loading';
+
+const PrivateRoute = ({ component: Component, ...otherProps }) => {
+ const { isAuthenticated, isLoading } = useContext(UserAuthContext);
+
+ return (
+
+ !isLoading ? (
+ isAuthenticated ? (
+
+ ) : (
+
+ )
+ ) : (
+ //
+ loading...
+ )
+ }
+ />
+ );
+};
+
+PrivateRoute.propTypes = {
+ component: PropTypes.func.isRequired
+};
+
+export default PrivateRoute;
diff --git a/jam-ui/src/helpers/rest.js b/jam-ui/src/helpers/rest.js
index 90cd9cf3e..291894218 100644
--- a/jam-ui/src/helpers/rest.js
+++ b/jam-ui/src/helpers/rest.js
@@ -51,13 +51,13 @@ export const getInstruments = () => {
})
}
-export const getCurrentUser = () => {
- return new Promise((resolve, reject) => {
- apiFetch('/me')
- .then(response => resolve(response))
- .catch(error => reject(error))
- })
-}
+// export const getCurrentUser = () => {
+// return new Promise((resolve, reject) => {
+// apiFetch('/me')
+// .then(response => resolve(response))
+// .catch(error => reject(error))
+// })
+// }
export const addFriend = (userId, friendId) => {
return new Promise((resolve, reject) => {
diff --git a/jam-ui/src/layouts/AuthBasicLayout.js b/jam-ui/src/layouts/AuthBasicLayout.js
index ea76f28cd..647beb0b6 100644
--- a/jam-ui/src/layouts/AuthBasicLayout.js
+++ b/jam-ui/src/layouts/AuthBasicLayout.js
@@ -3,15 +3,18 @@ import { Card, CardBody, Col, Row } from 'reactstrap';
import Logo from '../components/navbar/Logo';
import Section from '../components/common/Section';
import AuthBasicRoutes from '../components/auth/basic/AuthBasicRoutes';
+import UserAuth from '../context/UserAuth';
-const AuthBasicLayout = () => (
+const AuthBasicLayout = ({location}) => (
+
+
diff --git a/jam-ui/src/layouts/JKDashboardLayout.js b/jam-ui/src/layouts/JKDashboardLayout.js
index bab03c258..fa6907786 100644
--- a/jam-ui/src/layouts/JKDashboardLayout.js
+++ b/jam-ui/src/layouts/JKDashboardLayout.js
@@ -1,71 +1,22 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
-//import { Route, Redirect } from 'react-router-dom';
-import DashboardLoadingIndicator from '../components/dashboard/JKDashboardLoadingIndicator';
-import LoginRequest from '../components/auth/JKLoginRequest';
-import JKDashboard from '../components/dashboard/JKDashboardMain';
-
-import { useAuth } from '../context/AuthContext';
-import { getCurrentUser } from '../helpers/rest';
-
-const AUTH_STAGES = {
- loading: 1,
- authenticated: 2,
- unauthenticated: 3
-};
+//import DashboardLoadingIndicator from '../components/dashboard/JKDashboardLoadingIndicator';
+import Dashboard from '../components/dashboard/JKDashboardMain';
+import UserAuth from '../context/UserAuth';
const DashboardLayout = ({ location }) => {
-
- const { setCurrentUser } = useAuth();
- const [stage, setStage] = useState(AUTH_STAGES['loading']);
-
- useEffect(() => {
- getCurrentUser()
- .then(resp => {
- if (resp.ok) {
- return resp.json();
- }
- })
- .then(user => {
- setCurrentUser(user);
- window.currentUser = user;
- setStage(AUTH_STAGES['authenticated']);
- })
- .catch(error => {
- setStage(AUTH_STAGES['unauthenticated']);
- console.log(error);
- });
- }, [location.pathname]);
-
useEffect(() => {
window.scrollTo(0, 0);
}, [location.pathname]);
- switch (stage) {
- case AUTH_STAGES['authenticated']:
- return ;
- case AUTH_STAGES['unauthenticated']:
- return ;
- default:
- return ;
- }
+ return (
+
+
+
+ );
};
-// const ProtectedRoute = ({ component: Component, ...rest }) => {
-// const { currentUser } = useAuth();
-// return (
-// // Show the component only when the user is logged in
-// // Otherwise, redirect the user to /login page
-//
-// currentUser ? :
-// }
-// />
-// );
-// };
-
DashboardLayout.propTypes = { location: PropTypes.object.isRequired };
export default DashboardLayout;
diff --git a/jam-ui/src/layouts/JKDashboardRoutes.js b/jam-ui/src/layouts/JKDashboardRoutes.js
index 190268a2e..d5ba4a0b1 100644
--- a/jam-ui/src/layouts/JKDashboardRoutes.js
+++ b/jam-ui/src/layouts/JKDashboardRoutes.js
@@ -1,13 +1,15 @@
import React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
+import PrivateRoute from '../helpers/privateRoute';
+
import JKPeople from '../components/page/JKPeople';
import JKNotifications from '../components/page/JKNotifications';
const JKDashboardRoutes = () => (
-
-
+
+
{/*Redirect*/}
diff --git a/jam-ui/src/layouts/JKLayout.js b/jam-ui/src/layouts/JKLayout.js
index 1688c032a..c9539edfe 100644
--- a/jam-ui/src/layouts/JKLayout.js
+++ b/jam-ui/src/layouts/JKLayout.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useEffect} from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { toast, ToastContainer } from 'react-toastify';
import { CloseButton, Fade } from '../components/common/Toast';
@@ -7,11 +7,19 @@ import DashboardLayout from './JKDashboardLayout';
import ErrorLayout from './ErrorLayout';
import BuildMeta from "./JKBuildMeta";
+import loadable from '@loadable/component';
+const AuthBasicLayout = loadable(() => import('./AuthBasicLayout'));
+
const Layout = () => {
+ useEffect(() => {
+ AuthBasicLayout.preload();
+ }, []);
+
return (
}>
+
} position={toast.POSITION.BOTTOM_RIGHT} />
diff --git a/jam-ui/src/services/auth.js b/jam-ui/src/services/auth.js
new file mode 100644
index 000000000..9cee11f4b
--- /dev/null
+++ b/jam-ui/src/services/auth.js
@@ -0,0 +1,37 @@
+import { getCurrentUser } from '../helpers/rest';
+import apiFetch from "../helpers/apiFetch";
+import { reject } from 'lodash';
+
+export const checkIsAuthenticated = () => {
+ // return new Promise((resolve, reject) => {
+ // getCurrentUser()
+ // .then((resp) => resolve(resp.json()))
+ // .catch((err) => reject(err))
+ // });
+ return new Promise((resolve, reject) => {
+ apiFetch('/me')
+ .then(response => resolve(response))
+ .catch(error => reject(error))
+ })
+}
+
+export const authSignUp = () => {}
+
+export const authLogin = (credentials) => {
+ return new Promise((resolve, reject) => {
+ apiFetch('/auths/login', {
+ method: 'POST',
+ body: JSON.stringify(credentials)
+ })
+ .then(response => resolve(response))
+ .catch(error => reject(error))
+ })
+}
+
+export const authLogout = () => {
+ return new Promise((resolve, reject) => {
+ apiFetch('/auths/logout')
+ .then((response) => resolve(response))
+ .catch((error) => reject(error))
+ })
+}
\ No newline at end of file
diff --git a/web/app/controllers/api_auths_controller.rb b/web/app/controllers/api_auths_controller.rb
index b14894f78..8c37ab6e1 100644
--- a/web/app/controllers/api_auths_controller.rb
+++ b/web/app/controllers/api_auths_controller.rb
@@ -25,4 +25,9 @@ class ApiAuthsController < ApiController
}, :status => :ok
end
end
+
+ def logout
+ sign_out
+ render :json => {}, :status => :ok
+ end
end
diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb
index b7c4c4250..ba2353fa9 100644
--- a/web/app/controllers/api_users_controller.rb
+++ b/web/app/controllers/api_users_controller.rb
@@ -34,7 +34,14 @@ class ApiUsersController < ApiController
end
def me
- render json: { id: current_user.id, first_name: current_user.first_name, last_name: current_user.last_name, name: current_user.name, photo_url: current_user.photo_url }, status: 200
+ render json: {
+ id: current_user.id,
+ first_name: current_user.first_name,
+ last_name: current_user.last_name,
+ name: current_user.name,
+ email: current_user.email,
+ photo_url: current_user.photo_url
+ }, status: 200
end
def show
diff --git a/web/config/routes.rb b/web/config/routes.rb
index 629b668c6..6b1f615f7 100644
--- a/web/config/routes.rb
+++ b/web/config/routes.rb
@@ -252,6 +252,7 @@ Rails.application.routes.draw do
scope '/api' do
post '/auths/login' => 'api_auths#login'
+ post '/auths/logout' => 'api_auths#logout'
# live streams
match '/live_streams' => 'api_live_streams#index', :via => :get