Skip to content

Commit

Permalink
add logout functionality from storefront
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Kieckhafer <ek@ato.la>
Signed-off-by: Ross Hadden <rosshadden@gmail.com>
  • Loading branch information
kieckhafer authored and rosshadden committed Dec 20, 2019
1 parent 2e994c4 commit c8ac27e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions imports/plugins/core/layout/client/components/coreLayout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import { registerComponent, Components, composeWithTracker } from "@reactioncommerce/reaction-components";
import { Reaction } from "/client/api";
import { Reaction, Router } from "/client/api";
import Logger from "/client/modules/logger";
import { Meteor } from "meteor/meteor";
import Button from "@material-ui/core/Button";
Expand Down Expand Up @@ -36,7 +36,7 @@ const styles = (theme) => ({
* to operator 2.0
* @returns {Node} React component
*/
function CoreLayout({ classes, isAdmin, isLoading, isLoggedIn, location, storefrontHomeUrl }) {
function CoreLayout({ classes, isAdmin, isLoading, isLoggedIn, location, referer, storefrontHomeUrl }) {
const [isLoggingOut, setIsLoggingOut] = useState(false);

if (isLoading || isLoggingOut) return null;
Expand Down Expand Up @@ -83,6 +83,27 @@ function CoreLayout({ classes, isAdmin, isLoading, isLoggedIn, location, storefr
}
}


if (location.pathname.startsWith("/account/logout")) {
Meteor.logout();
if (referer) {
window.location.href = referer;
return null;
} else if (storefrontHomeUrl && storefrontHomeUrl.length) {
window.location.href = storefrontHomeUrl;
return null;
}

Logger.warn("Missing storefront home URL. Please set this from the shop settings panel so that customer users can be redirected to your storefront.");

content = (
<InlineAlert
alertType="error"
message="Missing storefront home URL. Please set this from the shop settings panel so that customer users can be redirected to your storefront."
/>
);
}

// If user is logged in, and they come from storefront (/account in url)
// redirect to storefront
if (location.pathname.startsWith("/account") && isLoggedIn) {
Expand Down Expand Up @@ -137,11 +158,13 @@ function composer(props, onData) {
const shop = Reaction.getCurrentShop();
const isLoading = (isAdmin !== true && isAdmin !== false) || !shop;
const isLoggedIn = !!Reaction.getUserId();
const referer = Router.current().query.referer;

onData(null, {
isAdmin,
isLoading,
isLoggedIn,
referer,
storefrontHomeUrl: (shop && shop.storefrontUrls && shop.storefrontUrls.storefrontHomeUrl) || null
});
}
Expand Down

0 comments on commit c8ac27e

Please sign in to comment.