diff options
| author | adamhrv <adam@ahprojects.com> | 2018-12-16 19:38:54 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-12-16 19:38:54 +0100 |
| commit | 23e9fef5dce8b0b15dd94713816b9d7d45f12356 (patch) | |
| tree | 3ca9ffe3adce76318450991bfc613073470b604c /client/util.js | |
| parent | 759027d5fbfd6665082f72a3ceaeef68c2d2142e (diff) | |
| parent | 6431d06048791763f3644b3a0457cc9c4f1df6d3 (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
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 {} - } -} |
