-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Button, EmptyStateCard, GU, Text, useTheme } from '@aragon/ui' | ||
import { EmptyWrapper } from '../Shared' | ||
import revoked from '../../assets/revoked.svg' | ||
|
||
const Illustration = () => <img src={revoked} alt="" /> | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🙃 |
||
const Revoked = ({ action }) => { | ||
const theme = useTheme() | ||
return ( | ||
<EmptyWrapper> | ||
<EmptyStateCard | ||
text={ | ||
<> | ||
<Text css={`margin: ${GU}px`}> | ||
Reconnect to GitHub | ||
</Text> | ||
<Text.Block | ||
size="small" | ||
color={`${theme.surfaceContentSecondary}`} | ||
> | ||
It seems that your connection to GitHub has been revoked; please | ||
reconnect. | ||
</Text.Block> | ||
</> | ||
} | ||
illustration={<Illustration />} | ||
action={<Button label="Sign in" onClick={action} />} | ||
/> | ||
</EmptyWrapper> | ||
) | ||
} | ||
|
||
Revoked.propTypes = { | ||
action: PropTypes.func.isRequired, | ||
} | ||
|
||
export default Revoked |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
import ApolloClient from 'apollo-boost' | ||
import { useAragonApi } from '../api-react' | ||
import { GITHUB_TOKEN_REVOKED } from '../store/eventTypes' | ||
import { STATUS } from '../utils/github' | ||
|
||
export const initApolloClient = token => | ||
new ApolloClient({ | ||
export const useApolloClient = () => { | ||
const { | ||
api, | ||
appState: { | ||
github: { token } = { token: null } | ||
} | ||
} = useAragonApi() | ||
if (token === null) return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return new ApolloClient({ | ||
uri: 'https://api.github.com/graphql', | ||
request: operation => { | ||
if (token) { | ||
operation.setContext({ | ||
headers: { | ||
accept: 'application/vnd.github.starfire-preview+json', // needed to create issues | ||
authorization: `bearer ${token}`, | ||
}, | ||
operation.setContext({ | ||
headers: { | ||
accept: 'application/vnd.github.starfire-preview+json', // needed to create issues | ||
authorization: `bearer ${token}`, | ||
}, | ||
}) | ||
}, | ||
onError: error => { | ||
if (error.networkError && error.networkError.statusCode === 401) { | ||
api.emitTrigger(GITHUB_TOKEN_REVOKED, { | ||
status: STATUS.REVOKED, | ||
scope: null, | ||
token: null, | ||
}) | ||
} | ||
}, | ||
else console.error(error) | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
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