diff --git a/README.md b/README.md index 2cd51e4..d4cd21d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli This app exports functions to be imported by other microapps. - `login` - redirects to login page +- `businessLogin` - redirects to business (i.e. customer) login page - `logout` - clears session storage and redirects to logout page - `setAppMenu` - sets sidebar menu for the app by app's `path` - `getAuthUserTokens` - returns a promise which resolves to object with user tokens `{ tokenV3, tokenV2 }` @@ -95,6 +96,7 @@ For example see https://github.com/topcoder-platform/micro-frontends-react-app ```js module.exports = { login: () => {}, + businessLogin: () => {}, logout: () => {}, setAppMenu: () => {}, getAuthUserTokens: () => new Promise(() => {}), @@ -121,6 +123,7 @@ For example see https://github.com/topcoder-platform/micro-frontends-angular-app ```js declare module '@topcoder/micro-frontends-navbar-app' { export const login: any; + export const businessLogin: any; export const logout: any; export const setAppMenu: any; export const getAuthUserTokens: any; diff --git a/src/topcoder-micro-frontends-navbar-app.js b/src/topcoder-micro-frontends-navbar-app.js index 5e146bd..f60723b 100644 --- a/src/topcoder-micro-frontends-navbar-app.js +++ b/src/topcoder-micro-frontends-navbar-app.js @@ -19,7 +19,7 @@ import { setNotificationPlatform, } from "./utils/exports"; -import { login, logout } from "./utils"; +import { login, businessLogin, logout } from "./utils"; import { PLATFORM } from "./constants/notifications"; const lifecycles = singleSpaReact({ @@ -37,6 +37,7 @@ export const { bootstrap, mount, unmount } = lifecycles; // list everything we want to export for other microapps here export { login, + businessLogin, logout, setAppMenu, getAuthUserTokens, diff --git a/src/utils/index.js b/src/utils/index.js index 5f37fa2..66be7c6 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -16,6 +16,16 @@ export const getLoginUrl = () => window.location.href.match(/[^?]*/)[0] )}`; +/** + * Generate Business Login URL + */ +export const getBusinessLoginUrl = () => + `${ + config.URL.AUTH + }?regSource=tcBusiness&mode=login&retUrl=${encodeURIComponent( + window.location.href.match(/[^?]*/)[0] + )}`; + /** * Logout user from Topcoder */ @@ -30,3 +40,10 @@ export const logout = () => { export const login = () => { window.location = getLoginUrl(); }; + +/** + * Forward user to business login page + */ +export const businessLogin = () => { + window.location = getBusinessLoginUrl(); +};