const React = require('react'); const createClass = require('create-react-class'); const Nav = require('naturalcrit/nav/nav.jsx'); const Account = createClass({ displayName : 'AccountNavItem', getInitialState : function() { return { url : '' }; }, componentDidMount : function(){ if(typeof window !== 'undefined'){ this.setState({ url : window.location.href }); } }, handleLogout : function(){ if(confirm('Are you sure you want to log out?')) { // Reset divider position window.localStorage.removeItem('naturalcrit-pane-split'); // Clear login cookie let domain = ''; if(window.location?.hostname) { let domainArray = window.location.hostname.split('.'); if(domainArray.length > 2){ domainArray = [''].concat(domainArray.slice(-2)); } domain = domainArray.join('.'); } document.cookie = `nc_session=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;samesite=lax;${domain ? `domain=${domain}` : ''}`; window.location = '/'; } }, render : function(){ if(global.account){ return {global.account.username} brews logout ; } return login ; } }); module.exports = Account;