From f670fda6c29cedaf4e1a7629886d83b3ff1a9ec8 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 11 Apr 2019 14:45:38 -0400 Subject: [PATCH] keep auth_token in a cookie on web --- package.json | 1 + src/ui/component/firstRun/view.jsx | 6 +++++- src/ui/index.jsx | 19 ++++++++++++------- yarn.lock | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0291c3bf8..d99ae413b 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "classnames": "^2.2.5", "codemirror": "^5.39.2", "connected-react-router": "^6.3.2", + "cookie": "^0.3.1", "copy-webpack-plugin": "^4.6.0", "country-data": "^0.0.31", "cross-env": "^5.2.0", diff --git a/src/ui/component/firstRun/view.jsx b/src/ui/component/firstRun/view.jsx index 5e83528c9..cae460251 100644 --- a/src/ui/component/firstRun/view.jsx +++ b/src/ui/component/firstRun/view.jsx @@ -121,7 +121,11 @@ export default class FirstRun extends PureComponent {

{__("Check out some of the neat content below me. I'll see you around!")}

-
diff --git a/src/ui/index.jsx b/src/ui/index.jsx index f0a16868e..f166791d3 100644 --- a/src/ui/index.jsx +++ b/src/ui/index.jsx @@ -21,17 +21,16 @@ import { import { Lbry, doToast, isURIValid, setSearchApi } from 'lbry-redux'; import { doDownloadLanguages, doUpdateIsNightAsync } from 'redux/actions/settings'; import { doAuthenticate, Lbryio, rewards, doBlackListedOutpointsSubscribe } from 'lbryinc'; -import( - /* webpackChunkName: "styles" */ - /* webpackPrefetch: true */ - 'scss/all.scss' -); import { store, history } from 'store'; import pjson from 'package.json'; import app from './app'; import analytics from './analytics'; import doLogWarningConsoleMessage from './logWarningConsoleMessage'; import { ConnectedRouter } from 'connected-react-router'; +import cookie from 'cookie'; +import(/* webpackChunkName: "styles" */ +/* webpackPrefetch: true */ +'scss/all.scss'); const APPPAGEURL = 'lbry://?'; @@ -67,7 +66,7 @@ Lbry.setDaemonConnectionString(SDK_API_URL); // We interect with ipcRenderer to get the auth key from a users keyring // We keep a local variable for authToken beacuse `ipcRenderer.send` does not // contain a response, so there is no way to know when it's been set -// @if TARGET='app' + let authToken; Lbryio.setOverride( 'setAuthToken', @@ -89,6 +88,9 @@ Lbryio.setOverride( const newAuthToken = response.auth_token; authToken = newAuthToken; + // @if TARGET='web' + document.cookie = cookie.serialize('authToken', authToken); + // @endif // @if TARGET='app' ipcRenderer.send('set-auth-token', authToken); // @endif @@ -112,10 +114,13 @@ Lbryio.setOverride( ipcRenderer.send('get-auth-token'); // @endif + // @if TARGET='web' + const { authToken } = cookie.parse(document.cookie); + resolve(authToken); + // @endif } }) ); -// @endif rewards.setCallback('claimFirstRewardSuccess', () => { app.store.dispatch(doOpenModal(MODALS.FIRST_REWARD)); diff --git a/yarn.lock b/yarn.lock index c6e720508..7c5102272 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2696,7 +2696,7 @@ cookie-signature@1.0.6: resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw= -cookie@0.3.1: +cookie@0.3.1, cookie@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=