diff --git a/jam-ui/.env.development.example b/jam-ui/.env.development.example index f72ec5e39..a54034cba 100644 --- a/jam-ui/.env.development.example +++ b/jam-ui/.env.development.example @@ -1,4 +1,5 @@ HOST=beta.jamkazam.local PORT=4000 +REACT_APP_ORIGIN=jamkazam.local REACT_APP_LEGACY_BASE_URL=http://www.jamkazam.local:3000 REACT_APP_API_BASE_URL=http://www.jamkazam.local:3000/api \ No newline at end of file diff --git a/jam-ui/.env.production b/jam-ui/.env.production index ba470e2f9..14fe4f7a1 100644 --- a/jam-ui/.env.production +++ b/jam-ui/.env.production @@ -1,4 +1,5 @@ HOST=beta.jamkazam.com PORT=4000 +REACT_APP_ORIGIN=jamkazam.com REACT_APP_LEGACY_BASE_URL=https://www.jamkazam.com REACT_APP_API_BASE_URL=https://www.jamkazam.com/api \ No newline at end of file diff --git a/jam-ui/cypress/integration/layout/navigation.spec.js b/jam-ui/cypress/integration/layout/navigation.spec.js index 60c6d0f91..67f6bc92d 100644 --- a/jam-ui/cypress/integration/layout/navigation.spec.js +++ b/jam-ui/cypress/integration/layout/navigation.spec.js @@ -39,6 +39,15 @@ describe("Top Navigation", () => { showSubscribeToUpdates() showProfileDropdown() }) + + it.only('sign out', () => { + + cy.get('[data-testid=navbarTopProfileDropdown]').contains('Peter Pan').trigger('mouseover') + cy.stubUnauthenticate() + cy.get('[data-testid=navbarTopProfileDropdown]').contains('Sign out').click() + cy.get('[data-testid=navbarTopProfileDropdown]').should('not.exist') + cy.contains("Sign in to begin") + }) }) describe('header notifications', () => { @@ -59,6 +68,5 @@ describe("Top Navigation", () => { }) }) - }); diff --git a/jam-ui/src/Main.js b/jam-ui/src/Main.js index c16ef7cce..c91277a12 100644 --- a/jam-ui/src/Main.js +++ b/jam-ui/src/Main.js @@ -7,6 +7,7 @@ import toggleStylesheet from './helpers/toggleStylesheet'; import { getItemFromStore, setItemToStore, themeColors } from './helpers/utils'; import store from './store/store'; import { Provider } from 'react-redux'; +import { CookiesProvider } from 'react-cookie'; const Main = props => { const [isFluid, setIsFluid] = useState(getItemFromStore('isFluid', settings.isFluid)); @@ -118,11 +119,13 @@ const Main = props => { } return - - - {props.children} - - + + + + {props.children} + + + ; }; diff --git a/jam-ui/src/components/auth/JKLoginRequest.js b/jam-ui/src/components/auth/JKLoginRequest.js index 3487a92dc..7521442be 100644 --- a/jam-ui/src/components/auth/JKLoginRequest.js +++ b/jam-ui/src/components/auth/JKLoginRequest.js @@ -12,7 +12,7 @@ function JKLoginRequest() { - Signin to begin + Sign in to begin Please sign in to your jamkazam account diff --git a/jam-ui/src/components/navbar/JKProfileDropdown.js b/jam-ui/src/components/navbar/JKProfileDropdown.js index 44dc374e9..6d4369abf 100644 --- a/jam-ui/src/components/navbar/JKProfileDropdown.js +++ b/jam-ui/src/components/navbar/JKProfileDropdown.js @@ -1,59 +1,59 @@ //import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import React, { useState, useEffect } from 'react'; -import { Link, useHistory } from 'react-router-dom'; +import React, { useState } from 'react'; +import { Link } from 'react-router-dom'; import { DropdownItem, DropdownMenu, DropdownToggle, Dropdown } from 'reactstrap'; import { useAuth } from '../../context/AuthContext'; 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 history = useHistory(); - //const [cookies, setCookie, removeCookie] = useCookies(['remember_token']); + const { currentUser, setCurrentUser } = useAuth(); + + const [cookies, setCookie, removeCookie] = useCookies(['remember_token']); - const handleLogout = () => { + const handleLogout = event => { + event.preventDefault(); + removeCookie('remember_token', { + domain: `.${process.env.REACT_APP_ORIGIN}` + }); setCurrentUser(null); - console.log("signout..."); - } - + window.location.reload(false); + }; return ( - <> - - { - let windowWidth = window.innerWidth; - windowWidth > 992 && setDropdownOpen(true); - }} - onMouseLeave={() => { - let windowWidth = window.innerWidth; - windowWidth > 992 && setDropdownOpen(false); - }} - > - - - - {currentUser && currentUser.name} - - - - - - My Profile - - - Sign out - - - - + {currentUser && + { + let windowWidth = window.innerWidth; + windowWidth > 992 && setDropdownOpen(true); + }} + onMouseLeave={() => { + let windowWidth = window.innerWidth; + windowWidth > 992 && setDropdownOpen(false); + }} + > + + + {currentUser && currentUser.name} + + + + + My Profile + + Sign out + + + + } > ); }; diff --git a/jam-ui/src/layouts/JKDashboardLayout.js b/jam-ui/src/layouts/JKDashboardLayout.js index 6b5abd7fe..09c753e8f 100644 --- a/jam-ui/src/layouts/JKDashboardLayout.js +++ b/jam-ui/src/layouts/JKDashboardLayout.js @@ -17,30 +17,30 @@ const AUTH_STAGES = { const DashboardLayout = ({ location }) => { - const { setCurrentUser } = useAuth(); + const { currentUser, setCurrentUser } = useAuth(); const [stage, setStage] = useState(AUTH_STAGES['loading']); const fetchCurrentUser = () => { 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); - }); + .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); + }); }; useEffect(() => { fetchCurrentUser(); - }, []); + }, [location.pathname]); useEffect(() => { window.scrollTo(0, 0);
Please sign in to your jamkazam account