Skip to content

Commit cbbd9ed

Browse files
committed
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.
1 parent 93848d3 commit cbbd9ed

File tree

13 files changed

+127
-25
lines changed

13 files changed

+127
-25
lines changed

apps/projects/app/App.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import {
1616
REQUESTED_GITHUB_TOKEN_FAILURE,
1717
} from './store/eventTypes'
1818

19-
import { initApolloClient } from './utils/apollo-client'
19+
import { useApolloClient } from './utils/apollo-client'
2020
import { getToken, githubPopup, STATUS } from './utils/github'
2121
import Unauthorized from './components/Content/Unauthorized'
2222
import { LoadingAnimation } from './components/Shared'
2323
import { EmptyWrapper } from './components/Shared'
24-
import { Error } from './components/Card'
24+
import { Error, Revoked } from './components/Card'
2525
import { DecoratedReposProvider } from './context/DecoratedRepos'
2626
import usePathSegments from './hooks/usePathSegments'
2727

@@ -50,13 +50,14 @@ const App = () => {
5050
const [ githubLoading, setGithubLoading ] = useState(false)
5151
const [ panel, setPanel ] = useState(null)
5252
const [ panelProps, setPanelProps ] = useState(null)
53+
const initApolloClient = useApolloClient()
5354

5455
const {
5556
github = { status : STATUS.INITIAL },
5657
isSyncing = true,
5758
} = appState
5859

59-
const client = github.token ? initApolloClient(github.token) : null
60+
const client = initApolloClient(github.token)
6061

6162
const handlePopupMessage = useCallback(message => {
6263
if (!popupRef) return
@@ -136,6 +137,12 @@ const App = () => {
136137
<Error action={noop} />
137138
</Main>
138139
)
140+
} else if (github.status === STATUS.REVOKED) {
141+
return (
142+
<Main>
143+
<Revoked action={handleGithubSignIn} />
144+
</Main>
145+
)
139146
}
140147

141148
return (

apps/projects/app/assets/revoked.svg

Lines changed: 24 additions & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Button, EmptyStateCard, GU, Text, useTheme } from '@aragon/ui'
4+
import { EmptyWrapper } from '../Shared'
5+
import revoked from '../../assets/revoked.svg'
6+
7+
const Illustration = () => <img src={revoked} alt="" />
8+
9+
10+
const Revoked = ({ action }) => {
11+
const theme = useTheme()
12+
return (
13+
<EmptyWrapper>
14+
<EmptyStateCard
15+
text={
16+
<>
17+
<Text css={`margin: ${GU}px`}>
18+
Reconnect to GitHub
19+
</Text>
20+
<Text.Block
21+
size="small"
22+
color={`${theme.surfaceContentSecondary}`}
23+
>
24+
It seems that your connection to GitHub has been revoked; please
25+
reconnect.
26+
</Text.Block>
27+
</>
28+
}
29+
illustration={<Illustration />}
30+
action={<Button label="Sign in" onClick={action} />}
31+
/>
32+
</EmptyWrapper>
33+
)
34+
}
35+
36+
Revoked.propTypes = {
37+
action: PropTypes.func.isRequired,
38+
}
39+
40+
export default Revoked

apps/projects/app/components/Card/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import Empty from './Empty'
22
import Project from './Project'
33
import Issue from './Issue'
44
import Error from './Error'
5-
export { Empty, Project, Issue, Error }
5+
import Revoked from './Revoked'
6+
export { Empty, Project, Issue, Error, Revoked }

apps/projects/app/components/Content/IssueDetail/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { useQuery } from '@apollo/react-hooks'
1313
import useShapedIssue from '../../../hooks/useShapedIssue'
1414
import { GET_ISSUE } from '../../../utils/gql-queries.js'
15-
import { initApolloClient } from '../../../utils/apollo-client'
15+
import { useApolloClient } from '../../../utils/apollo-client'
1616
import EventsCard from './EventsCard'
1717
import DetailsCard from './DetailsCard'
1818
import BountyCard from './BountyCard'
@@ -45,12 +45,12 @@ Wrap.propTypes = {
4545

4646
const IssueDetail = ({ issueId }) => {
4747
const { appState: { github } } = useAragonApi()
48+
const initApolloClient = useApolloClient()
4849
const client = useMemo(() => initApolloClient(github.token), [])
4950
const { layoutName } = useLayout()
5051
const shapeIssue = useShapedIssue()
5152
const { loading, error, data } = useQuery(GET_ISSUE, {
5253
client,
53-
onError: console.error,
5454
variables: { id: issueId },
5555
})
5656
if (loading) return <Wrap>Loading...</Wrap>

apps/projects/app/components/Content/Issues.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useAragonApi } from '../../api-react'
77
import { Button, GU, Header, IconPlus, Text } from '@aragon/ui'
88
import { compareAsc, compareDesc } from 'date-fns'
99

10-
import { initApolloClient } from '../../utils/apollo-client'
10+
import { useApolloClient } from '../../utils/apollo-client'
1111
import useShapedIssue from '../../hooks/useShapedIssue'
1212
import usePathSegments from '../../hooks/usePathSegments'
1313
import { STATUS } from '../../utils/github'
@@ -350,7 +350,7 @@ class Issues extends React.PureComponent {
350350
}
351351

352352
const IssuesQuery = ({ client, query, ...props }) => {
353-
const graphqlQuery = useQuery(query, { client, onError: console.error })
353+
const graphqlQuery = useQuery(query, { client })
354354
return <Issues graphqlQuery={graphqlQuery} {...props} />
355355
}
356356

@@ -360,6 +360,7 @@ IssuesQuery.propTypes = {
360360
}
361361

362362
const IssuesWrap = props => {
363+
const initApolloClient = useApolloClient()
363364
const { appState } = useAragonApi()
364365
const {
365366
repos,
@@ -417,7 +418,8 @@ const IssuesWrap = props => {
417418
}, [ downloadedRepos, filters, repos ])
418419

419420
useEffect(() => {
420-
setClient(github.token ? initApolloClient(github.token) : null)
421+
const apolloClient = initApolloClient(github.token)
422+
setClient(apolloClient)
421423
}, [github.token])
422424

423425
return (

apps/projects/app/components/Panel/NewIssue/NewIssue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class NewIssue extends React.PureComponent {
110110
<Mutation
111111
mutation={NEW_ISSUE}
112112
variables={{ title, description, id }}
113-
onError={console.error}
114113
>
115114
{(newIssue, result) => {
116115
const { data, loading, error, called } = result

apps/projects/app/components/Panel/NewProject/NewProject.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ const NewProject = () => {
123123
<Query
124124
fetchPolicy="cache-first"
125125
query={GET_REPOSITORIES}
126-
onError={console.error}
127126
>
128127
{({ data, loading, error, refetch }) => {
129128
if (data && data.viewer) {

apps/projects/app/hooks/useGithubAuth.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useEffect, useState } from 'react'
22
import { useAragonApi } from '../api-react'
3-
import { initApolloClient } from '../utils/apollo-client'
3+
import { useApolloClient } from '../utils/apollo-client'
44
import { CURRENT_USER } from '../utils/gql-queries'
55

66
const useGithubAuth = () => {
77
const { appState } = useAragonApi()
8+
const initApolloClient = useApolloClient()
89
const token = appState.github && appState.github.token
910

1011
const [ githubCurrentUser, setGithubCurrentUser ] = useState({})

apps/projects/app/store/eventTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const REQUESTING_GITHUB_TOKEN = 'Requesting_GitHub_Token'
33
export const REQUESTED_GITHUB_TOKEN_SUCCESS = 'Requesting_GitHub_Token_Success'
44
export const REQUESTED_GITHUB_TOKEN_FAILURE = 'Requesting_GitHub_Token_Failure'
55
export const REQUESTED_GITHUB_DISCONNECT = 'Requested_GitHub_Disconnect'
6+
export const GITHUB_TOKEN_REVOKED = 'Github_Token_Revoked'
67

78
/* Projects.sol events */
89
export const REPO_ADDED = 'RepoAdded'

0 commit comments

Comments
 (0)