UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

63 lines (62 loc) 2.08 kB
import { useState as c, useEffect as w } from "react"; import a from "universal-cookie"; import { ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY as l, LAST_PLACE_LOCALSTORAGE_KEY as r } from "../SynapseConstants.js"; function f() { localStorage.setItem(r, window.location.href); } const i = "org.sagebionetworks.cookies.redirect-after-login", s = () => { if (window.location.hostname.toLowerCase().endsWith(".synapse.org")) return ".synapse.org"; if (window.location.hostname.toLowerCase().endsWith(".dev.sagebase.org")) return ".dev.sagebase.org"; }; function m(e) { const t = new a(), n = /* @__PURE__ */ new Date(); n.setTime(n.getTime() + 3600 * 1e3), t.set(i, window.location.href, { path: "/", domain: s(), expires: n }), setTimeout(() => { window.location.assign(e); }, 10); } function p() { const e = new a(), t = /* @__PURE__ */ new Date(); if (t.setMinutes(t.getMinutes() + 1), e.set(l, "true", { path: "/", expires: t, domain: s() }), e.get(i)) { const n = e.get(i), o = /* @__PURE__ */ new Date(); return o.setTime(o.getTime() + 10 * 1e3), e.set(i, n, { path: "/", domain: s(), expires: o }), window.location.replace(n), !0; } return !1; } function h(e, t) { const n = localStorage.getItem(r); localStorage.removeItem(r); const o = n ?? t; return o && window.location.href != o && window.location.href.substring(window.location.origin.length) != o ? (e ? o.startsWith(window.location.origin) ? e(o.substring(window.location.origin.length), { replace: !0 }) : e(o, { replace: !0 }) : window.location.replace(o), !0) : !1; } function E() { const [e, t] = c(!1); return w(() => { window.top && window.top !== window && (t(!0), window.top.location.href = window.location.toString()); }, []), e; } export { i as ONE_SAGE_REDIRECT_COOKIE_KEY, s as getCookieDomain, p as processRedirectURLInOneSage, h as restoreLastPlace, f as storeLastPlace, m as storeRedirectURLForOneSageLoginAndGotoURL, E as useFramebuster }; //# sourceMappingURL=AppUtils.js.map