diff --git a/web/app/common/constants.js b/web/app/common/constants.js index 77937f25..a4e1ef28 100644 --- a/web/app/common/constants.js +++ b/web/app/common/constants.js @@ -38,3 +38,29 @@ export const BLOCKING_DURATIONS = [ value: `${60 * 24}m`, }, ]; + +/** + * Defines if browser storage features (cookies, localsrotage) + * are available or blocked via browser preferences + */ +export const STORAGE_AVAILABLE = (() => { + try { + localStorage.setItem('localstorage_availability_test', null); + localStorage.removeItem('localstorage_availability_test'); + } catch (e) { + return false; + } + return true; +})(); + +/** + * Defines whether iframe loaded in cross origin environment + * Usefull for checking if some privacy restriction may be applied + */ +export const IS_THIRD_PARTY = (() => { + try { + return window.parent.document.location.host !== window.location.host; + } catch (e) { + return true; + } +})(); diff --git a/web/app/common/localStorage.js b/web/app/common/localStorage.js new file mode 100644 index 00000000..417f7dc4 --- /dev/null +++ b/web/app/common/localStorage.js @@ -0,0 +1,30 @@ +export const isAvailable = (() => { + try { + localStorage.setItem('localstorage_availability_test', null); + localStorage.removeItem('localstorage_availability_test'); + } catch (e) { + return false; + } + return true; +})(); + +const failMessage = 'remark42: localStorage access denied, check browser preferences'; + +export const setItem = isAvailable + ? localStorage.setItem.bind(localStorage) + : () => { + console.error(failMessage); // eslint-disable-line no-console + }; + +export const getItem = isAvailable + ? localStorage.getItem.bind(localStorage) + : () => { + console.error(failMessage); // eslint-disable-line no-console + return null; + }; + +export const removeItem = isAvailable + ? localStorage.removeItem.bind(localStorage) + : () => { + console.error(failMessage); // eslint-disable-line no-console + }; diff --git a/web/app/components/auth-panel/auth-panel.jsx b/web/app/components/auth-panel/auth-panel.jsx index 2ed169dc..1cc5ef76 100644 --- a/web/app/components/auth-panel/auth-panel.jsx +++ b/web/app/components/auth-panel/auth-panel.jsx @@ -4,7 +4,7 @@ import { h, Component } from 'preact'; import UserId from './__user-id/auth-panel__user-id'; import Dropdown, { DropdownItem } from 'components/dropdown'; import Button from 'components/button'; -import { PROVIDER_NAMES } from 'common/constants'; +import { PROVIDER_NAMES, STORAGE_AVAILABLE, IS_THIRD_PARTY } from 'common/constants'; import { requestDeletion } from 'utils/email'; import { getHandleClickProps } from 'common/accessibility'; @@ -76,28 +76,46 @@ export default class AuthPanel extends Component { )} - {!loggedIn && ( -