2020-05-25 23:38:52 +00:00
|
|
|
import { UseNotifierResult } from "@saleor/hooks/useNotifier";
|
|
|
|
import { commonMessages } from "@saleor/intl";
|
|
|
|
import { IntlShape } from "react-intl";
|
|
|
|
|
2019-09-03 13:42:15 +00:00
|
|
|
const TOKEN_STORAGE_KEY = "dashboardAuth";
|
|
|
|
|
|
|
|
export const getAuthToken = () =>
|
|
|
|
localStorage.getItem(TOKEN_STORAGE_KEY) ||
|
|
|
|
sessionStorage.getItem(TOKEN_STORAGE_KEY);
|
|
|
|
|
|
|
|
export const setAuthToken = (token: string, persist: boolean) =>
|
|
|
|
persist
|
|
|
|
? localStorage.setItem(TOKEN_STORAGE_KEY, token)
|
|
|
|
: sessionStorage.setItem(TOKEN_STORAGE_KEY, token);
|
|
|
|
|
|
|
|
export const removeAuthToken = () => {
|
|
|
|
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
|
|
sessionStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
|
|
};
|
2020-05-25 23:38:52 +00:00
|
|
|
|
|
|
|
export const displayDemoMessage = (
|
|
|
|
intl: IntlShape,
|
|
|
|
notify: UseNotifierResult
|
|
|
|
) => {
|
|
|
|
notify({
|
|
|
|
text: intl.formatMessage(commonMessages.demo)
|
|
|
|
});
|
|
|
|
};
|