diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-12-15 23:21:02 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-12-15 23:21:02 +0100 |
| commit | fe303999bb3d1067783ea96cef71ea2a4a69a2df (patch) | |
| tree | c76af2b4ed724984953ac4b91f9452ba63d13370 /client/util.js | |
| parent | a53a598461a25e8bf1d0bd3e63c47642e3213aef (diff) | |
embedding applets
Diffstat (limited to 'client/util.js')
| -rw-r--r-- | client/util.js | 26 |
1 files changed, 1 insertions, 25 deletions
diff --git a/client/util.js b/client/util.js index 92b4addc..50d4992a 100644 --- a/client/util.js +++ b/client/util.js @@ -7,6 +7,7 @@ export const isMobile = isiPhone || isiPad || isAndroid export const isDesktop = !isMobile export const toArray = a => Array.prototype.slice.apply(a) +export const choice = a => a[Math.floor(Math.random() * a.length)] const htmlClassList = document.body.parentNode.classList htmlClassList.add(isDesktop ? 'desktop' : 'mobile') @@ -142,28 +143,3 @@ export const post = (uri, data, credentials) => { // headers['X-CSRFToken'] = csrftoken return fetch(uri, opt).then(res => res.json()) } - -// api queries -export const login = () => { - if (cachedAuth) return cachedAuth - const isLocal = (window.location.hostname === '0.0.0.0' || window.location.hostname === '127.0.0.1') - try { - const auth = JSON.parse(JSON.parse(localStorage.getItem('persist:root')).auth) - // console.log('auth', auth) - token = auth.token - username = auth.user.username - if (token) { - console.log('logged in', username) - } - cachedAuth = auth - if (!token && !isLocal) { - window.location.href = '/' - } - return auth - } catch (e) { - if (!isLocal) { - window.location.href = '/' - } - return {} - } -} |
