-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(projects): handle GitHub token revocation
When a GitHub request is made with a revoked token, the end user is informed and asked to sign in again.
- Loading branch information
Showing
13 changed files
with
127 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="" /> | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
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({ | ||
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}`, | ||
}, | ||
}) | ||
export const useApolloClient = () => { | ||
const { api } = useAragonApi() | ||
const initApolloClient = token => { | ||
if (token === null) return null | ||
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}`, | ||
}, | ||
}) | ||
} | ||
}, | ||
onError: error => { | ||
if (error.networkError && error.networkError.statusCode === 401) { | ||
api.emitTrigger(GITHUB_TOKEN_REVOKED, { | ||
status: STATUS.REVOKED, | ||
scope: null, | ||
token: null, | ||
}) | ||
} | ||
} | ||
}, | ||
}) | ||
}) | ||
} | ||
return initApolloClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters