Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle GitHub token revocation #1849

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Handle GitHub token revocation #1849

wants to merge 2 commits into from

Conversation

e18r
Copy link
Contributor

@e18r e18r commented Jan 7, 2020

Fixes #654

When a GitHub request is made with a revoked token, the end user is informed and asked to sign in again.

Peek 2020-01-07 10-12

@e18r e18r requested a review from chadoh January 7, 2020 15:48
@e18r e18r requested a review from a team as a code owner January 7, 2020 15:48
@ghost ghost removed their request for review January 7, 2020 15:48
})
})
}
return initApolloClient
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can save all consumers of useApolloClient a line or two by doing something like this:

export const useApolloClient = () => {
  const { api, appState } = useAragonApi()
  if (appState.github.token === null) return null
  return new ApolloClient({ ... })
}

Note that there's also no reason to pass token in as an argument anymore, now that this is a hook!

Do you think this would work? Is there a reason to make this return an initApolloClient function, rather than null or an actual client?

scope: null,
token: null,
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an else with console.error(error), to keep the functionality we had before and make sure these errors are still visible in the console

@chadoh chadoh assigned e18r and unassigned chadoh Jan 13, 2020
@e18r e18r requested a review from chadoh January 15, 2020 19:49
@e18r e18r assigned chadoh and unassigned e18r Jan 15, 2020
@e18r
Copy link
Contributor Author

e18r commented Jan 15, 2020

Hey @chadoh, this PR is ready for another round of review. Thanks!

When a GitHub request is made with a revoked token, the end user is
informed and asked to sign in again.
Previously, in order to use the Github API client, you had to:

1. Get the GitHub token from the appState
2. Call the `useApolloClient` hook and get the `initApolloClient` function
3. Call the `initApolloClient` function with the GitHub token as an
argument and get the client

But since `useApolloClient` is a hook, this commit simplifies it so
that the appState is accessed directly from within the hook, and the
actual API client is returned directly, so that the above steps get
simplified to:

1. Call the `useApolloClient` hook and get the client
@e18r
Copy link
Contributor Author

e18r commented Jan 17, 2020

Rebased with dev and solved several conflicts.

Copy link
Collaborator

@chadoh chadoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice! I see a couple more small improvements we could make, which would not require the "request changes" status, but I also see something else...

The IssueDetail page doesn't work! I haven't looked into why, but it works on dev and is broken on this branch.

import PropTypes from 'prop-types'
import { Button, EmptyStateCard, GU, Text, useTheme } from '@aragon/ui'
import { EmptyWrapper } from '../Shared'
import revoked from '../../assets/revoked.svg'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we export a component, instead of raw SVG? Like we did for IconDoubleCheck in Allocations


const Illustration = () => <img src={revoked} alt="" />


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our linter doesn't complain about two line breaks in a row so I guess I have to 🙃

github: { token } = { token: null }
}
} = useAragonApi()
if (token === null) return null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all a bit weird to read. How about:

const { api, appState: { github } } = useAragonApi()
if (!github || !github.token) return null

Then we'll have to use github.token elsewhere, but I think that's a good balance of readability here vs terseness there.

@chadoh chadoh assigned e18r and unassigned chadoh Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clear Stale GitHub Token from cache
2 participants