forked from consensolabs/dapp-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect.js
43 lines (37 loc) · 1.15 KB
/
Connect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint-disable prettier/prettier */
import React, { useEffect } from 'react'
import { Button } from '@aragon/ui'
function Connect() {
const CLIENT_ID = '69bc88033c4b1bc2b4dc'
const REDIRECT_URI = 'http://localhost:3000/dashboard'
useEffect(() => {
const code =
window.location.href.match(/\?code=(.*)/) &&
window.location.href.match(/\?code=(.*)/)[1]
console.log(window.location.href)
console.log(code)
// console.log(screen.id)
fetch(`https://gitfund-oauth.herokuapp.com/authenticate/${code}`)
.then((response) => response.json())
.then(({ token }) => {
console.log(token)
console.log(token)
localStorage.setItem('GithubToken', token)
})
}, [])
return (
<>
<a
style={{ textDecoration: 'none' }}
href={`https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&scope=user&redirect_uri=${REDIRECT_URI}`}
>
{localStorage.getItem('GithubToken') === 'undefined' ? (
<Button mode='normal' label='CONNECT' />
) : (
<Button mode='positive' label='CONNECTED' />
)}
</a>
</>
)
}
export default Connect