diff options
Diffstat (limited to 'client/util.js')
| -rw-r--r-- | client/util.js | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/client/util.js b/client/util.js index ad303c64..50d4992a 100644 --- a/client/util.js +++ b/client/util.js @@ -6,6 +6,9 @@ export const isAndroid = !!(navigator.userAgent.match(/Android/i)) 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') @@ -140,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 {} - } -} |
