diff options
Diffstat (limited to 'vnext/src/index.js')
-rw-r--r-- | vnext/src/index.js | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/vnext/src/index.js b/vnext/src/index.js index aeb5357f..9527178e 100644 --- a/vnext/src/index.js +++ b/vnext/src/index.js @@ -20,19 +20,16 @@ class App extends React.Component { super(props); let params = qs.parse(window.location.search) if (params.hash) { - window.localStorage.hash = params.hash window.history.replaceState({}, document.title, `${window.location.protocol}//${window.location.host}${window.location.pathname}`) } this.state = { - visitor: { - uid: Number(window.localStorage.uid) || 0, - hash: window.localStorage.hash || params.hash || '' + visitor: localStorage.visitor ? JSON.parse(localStorage.visitor) : { + uid: 0, + hash: params.hash || '' } }; } - componentDidMount() { - this.auth(this.state.visitor.hash) - } + render() { const user = this.state.visitor; return ( @@ -156,25 +153,10 @@ class App extends React.Component { </Router> ) } - auth = (data) => { - if (data) { - window.localStorage.hash = data; - fetch(`https://api.juick.com/users?hash=${data}`) - .then(response => { - return response.json() - }) - .then(users => { - let visitor = users[0]; - visitor.hash = data; - window.localStorage.uid = visitor.uid; - this.setState({ - visitor: visitor - }) - }).catch(reason => { - window.localStorage.clear() - window.location.reload() - }) - } + auth = (visitor) => { + this.setState({ + visitor: visitor + }) } } |