Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

feat: add businessLogin function #28

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`
Expand Down Expand Up @@ -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(() => {}),
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/topcoder-micro-frontends-navbar-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
};