Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kdoran/lookout
Browse files Browse the repository at this point in the history
  • Loading branch information
kdoran committed Apr 7, 2020
2 parents ac00880 + 75c072a commit 013e63c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ class UserRoutes extends Component {
async componentDidMount () {
const { couchUrl } = this.state
const { userCtx } = await fetcher.checkSession(couchUrl)
if (userCtx.name || userCtx.roles.length) {
this.onAuthenticated(userCtx)
const authenticated = userCtx.name || userCtx.roles.includes('_admin')

if (!authenticated) {
this.setState({loading: false})
return
}

const dbs = await fetcher.get(`${couchUrl}_all_dbs`, { limit: LIMIT })
this.setState({ loading: false, dbs })
this.onAuthenticated(userCtx)
}

onAuthenticated = (userCtx) => {
// TODO: this cache object was never used much
onAuthenticated = async (userCtx) => {
const { couchUrl } = this.state
Object.assign(cache.userCtx, userCtx)
this.setState({ authenticated: true })
const dbs = await fetcher.get(`${couchUrl}_all_dbs`, { limit: LIMIT })
this.setState({ loading: false, dbs, authenticated: true })
}

render () {
Expand Down
2 changes: 1 addition & 1 deletion app/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class LoginContainer extends React.Component {
<div>{couchUrl} <Link to='/'>change couch</Link></div>
<input autoFocus type='text' ref='username' /> <br />
<input type='password' ref='password' />
{error && <pre className='error'>{JSON.stringify(error, null, 2)}</pre>} <br />
{error && <pre className='error'>{error.message ? error.message : JSON.stringify(error, null, 2)}</pre>} <br />
<button disabled={loading} type='submit'>{loading ? 'Loading...' : 'Submit'}</button> <br />
</form>
)
Expand Down

0 comments on commit 013e63c

Please sign in to comment.