diff --git a/package.json b/package.json index 27d0c20..2535916 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,14 @@ }, "dependencies": { "app-root-path": "^2.0.1", + "axios": "^0.17.1", "classnames": "^2.2.5", "electron-is-dev": "^0.3.0", "electron-next": "^3.1.3", "fs-extra": "^5.0.0", "path-exists": "^3.0.0", "prop-types": "^15.6.0", + "react-cookies": "^0.1.0", "react-hash-avatar": "^0.0.2", "react-render-html": "^0.6.0", "react-sortable-hoc": "^0.6.8", diff --git a/renderer/pages/start.js b/renderer/pages/start.js index c5be2ec..19201a6 100644 --- a/renderer/pages/start.js +++ b/renderer/pages/start.js @@ -11,13 +11,17 @@ import Page from './../layouts/page' // Components import Row from './../components/row' +// Services +import { getCookie } from './../services/cookies' + // Theme import { colors, typography } from './../theme' class Start extends Component { componentDidMount() { - const isPro = remote && remote.app ? remote.app.config.user.pro : false - const redirectUrl = isPro ? '/login' : '/onboard' + const cfg = remote && remote.app ? remote.app.config : {} + const token = getCookie('taskr') + const redirectUrl = cfg.user.pro && token ? '/home?tab=Today' : '/onboard' Router.push(redirectUrl) } diff --git a/renderer/services/api.js b/renderer/services/api.js index 4f49edb..38999d9 100644 --- a/renderer/services/api.js +++ b/renderer/services/api.js @@ -1,7 +1,7 @@ 'use strict' // Packages -const uid = require('uid-promise') +import uid from 'uid-promise' export const getUser = () => { const storage = JSON.parse(localStorage.getItem('taskr')) diff --git a/renderer/services/cookies.js b/renderer/services/cookies.js new file mode 100644 index 0000000..c7fc9f8 --- /dev/null +++ b/renderer/services/cookies.js @@ -0,0 +1,21 @@ +'use strict' + +import cookie from 'react-cookies' + +export const getCookie = key => { + return cookie.load(key) +} + +export const setCookie = value => { + const now = new Date() + now.setDate(now.getDate() + 14) + + return cookie.save('taskr', value, { + expires: now, + path: '/' + }) +} + +export const logout = () => { + return cookie.remove('taskr', { path: '/' }) +} diff --git a/yarn.lock b/yarn.lock index 5a994e9..6e037cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -393,6 +393,13 @@ aws4@^1.2.1, aws4@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" +axios@^0.17.1: + version "0.17.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.17.1.tgz#2d8e3e5d0bdbd7327f91bc814f5c57660f81824d" + dependencies: + follow-redirects "^1.2.5" + is-buffer "^1.1.5" + babel-code-frame@^6.16.0, babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -1606,6 +1613,10 @@ convert-source-map@1.5.1, convert-source-map@^1.5.0: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" +cookie@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" + core-assert@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/core-assert/-/core-assert-0.2.1.tgz#f85e2cf9bfed28f773cc8b3fa5c5b69bdc02fe3f" @@ -2666,6 +2677,12 @@ follow-redirects@1.2.6: dependencies: debug "^3.1.0" +follow-redirects@^1.2.5: + version "1.3.0" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.3.0.tgz#f684871fc116d2e329fda55ef67687f4fabc905c" + dependencies: + debug "^3.1.0" + for-in@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -5206,6 +5223,13 @@ react-attr-converter@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/react-attr-converter/-/react-attr-converter-0.3.1.tgz#4a2abf6d907b7ddae4d862dfec80e489ce41ad6e" +react-cookies@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/react-cookies/-/react-cookies-0.1.0.tgz#6bb883f2d1a397f138a4110300b46fe25df8f1a9" + dependencies: + cookie "^0.3.1" + object-assign "^4.1.1" + react-deep-force-update@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.1.1.tgz#8ea4263cd6455a050b37445b3f08fd839d86e909"