Skip to content

Commit 7633e73

Browse files
committed
authenticate using netlify
1 parent f8a24f9 commit 7633e73

File tree

6 files changed

+80
-99
lines changed

6 files changed

+80
-99
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"fs-extra": "3.0.1",
2828
"html-webpack-plugin": "2.29.0",
2929
"jest": "20.0.4",
30+
"netlify-auth-providers": "^1.0.0-alpha5",
3031
"object-assign": "4.1.1",
3132
"postcss-flexbugs-fixes": "3.2.0",
3233
"postcss-loader": "2.0.8",

src/GitHub/GitHub.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
22
import Loading from '../Components/Loading';
3-
import { githubAccessTokenUrl } from './constants'
43

54
class GitHub extends React.Component {
65
constructor(props) {
@@ -14,33 +13,6 @@ class GitHub extends React.Component {
1413
};
1514
}
1615

17-
async componentDidMount() {
18-
fetch(new Request(
19-
'https://api.github.com/users/lucassabreu',
20-
{
21-
method: "GET",
22-
headers: new Headers({ accept: 'application/json' })
23-
})
24-
)
25-
.then(r => r.json())
26-
.then(console.log)
27-
28-
fetch(new Request(
29-
githubAccessTokenUrl(this.state.code),
30-
{
31-
method: 'POST',
32-
headers: new Headers({ Accept: 'application/json' })
33-
}
34-
))
35-
.then(r => {
36-
if (r.ok === false) {
37-
throw new Error(`${r.status} - ${r.statusText}`)
38-
}
39-
return r.json()
40-
})
41-
.then(console.log())
42-
}
43-
4416
render() {
4517
const { loading } = this.state;
4618
return (

src/GitHub/constants.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Home.js

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,80 @@ import { withRouter } from 'react-router-dom';
44
import githubLogo from './assets/images/github.svg'
55
import gitlabLogo from './assets/images/gitlab.svg'
66
import trelloLogo from './assets/images/trello.svg'
7+
import Authenticator from 'netlify-auth-providers';
8+
import { UncontrolledTooltip } from 'reactstrap';
79
import './Home.css'
8-
import { githubAuthorizeUrl } from './GitHub/constants';
910

10-
const callbackUrl = (setupable) => `${window.location.href}${setupable}/callback`
11-
const SETUPABLE = [
12-
{
13-
name: "GitHub",
14-
logo: githubLogo,
15-
enabled: true,
16-
url: githubAuthorizeUrl(callbackUrl('github')),
17-
},
18-
{
19-
name: "GitLab",
20-
logo: gitlabLogo,
21-
enabled: false,
22-
url: null,
23-
},
24-
{
25-
name: "Trello",
26-
logo: trelloLogo,
27-
enabled: false,
28-
url: null,
29-
},
30-
];
11+
const nullCallback = (event) => event.preventDefault();
12+
const auth = new Authenticator({ site_id: "cwps.lucassabreu.net.br" });
3113

32-
const Home = () => (
33-
<div className="Home">
34-
<section className="description">
35-
<p>
36-
This web client helps to setup a project at GitHub, GitLab or Trello to use the
37-
Coderockr Way's labels, making easier to bootstrap the basic configuration at
38-
your project.
39-
</p>
40-
</section>
41-
<section className="project-handlers">
42-
<h2>Where is your project?</h2>
43-
<ul className="row project-handlers-buttons justify-content-md-center">
44-
{SETUPABLE.map(({ name, logo: Logo, url, enabled }) => (
45-
<li key={name} className="col-md-4">
46-
<a className={`btn btn-primary ${enabled ? null : 'disabled'}`} href={url}
47-
alt={enabled ? '' : `${name} will be supported soon`}>
48-
<Logo className="icon" />
49-
{name}
50-
</a>
51-
</li>
52-
))}
53-
</ul>
54-
</section>
55-
<section className="more-about">
56-
<h4>Wanna know more about?</h4>
57-
<p>Look this link: <a href="https://blog.coderockr.com/simplificando-o-setup-de-projetos-no-github-f29b76c83194">Simplificando o Setup de Projetos no GitHub</a>
14+
const Home = ({ history }) => {
15+
const origins = [
16+
{
17+
name: "GitHub",
18+
logo: githubLogo,
19+
enabled: true,
20+
callback: (event) => {
21+
auth.authenticate({ provider: "github", scope: "user" }, (err, data) => {
22+
if (err) {
23+
console.error(err);
24+
return
25+
}
26+
sessionStorage.setItem('github-token', data.token);
27+
history.push('/github');
28+
})
29+
}
30+
},
31+
{
32+
name: "GitLab",
33+
logo: gitlabLogo,
34+
enabled: false,
35+
callback: nullCallback,
36+
},
37+
{
38+
name: "Trello",
39+
logo: trelloLogo,
40+
enabled: false,
41+
callback: nullCallback,
42+
},
43+
];
44+
45+
return (
46+
<div className="Home">
47+
<section className="description">
48+
<p>
49+
This web client helps to setup a project at GitHub, GitLab or Trello to use the
50+
Coderockr Way's labels, making easier to bootstrap the basic configuration at
51+
your project.
5852
</p>
59-
</section>
60-
</div>
61-
)
53+
</section>
54+
<section className="project-handlers">
55+
<h2>Where is your project?</h2>
56+
<ul className="row project-handlers-buttons justify-content-md-center">
57+
{origins.map(({ name, logo: Logo, callback, enabled }) => (
58+
<li key={name} className="col-md-4">
59+
<button id={`btn_origin_${name}`} className={`btn btn-primary ${enabled ? null : 'disabled'}`}
60+
onClick={(event) => callback(event)}
61+
>
62+
<Logo className="icon" />
63+
{name}
64+
</button>
65+
{enabled ? null :
66+
<UncontrolledTooltip placement="bottom" target={`btn_origin_${name}`} >
67+
{name} will be supported soon
68+
</UncontrolledTooltip>
69+
}
70+
</li>
71+
))}
72+
</ul>
73+
</section>
74+
<section className="more-about">
75+
<h4>Wanna know more about?</h4>
76+
<p>Look this link: <a href="https://blog.coderockr.com/simplificando-o-setup-de-projetos-no-github-f29b76c83194">Simplificando o Setup de Projetos no GitHub</a>
77+
</p>
78+
</section>
79+
</div>
80+
)
81+
}
6282

6383
export default withRouter(Home);

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ a:hover {
7171
color: var(--primary);
7272
}
7373

74+
.btn.btn-primary.disabled:hover {
75+
color: white;
76+
}
77+
7478
.btn-primary:hover {
7579
background-color: var(--primary);
7680
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,6 +4248,10 @@ negotiator@0.6.1:
42484248
version "0.6.1"
42494249
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
42504250

4251+
netlify-auth-providers@^1.0.0-alpha5:
4252+
version "1.0.0-alpha5"
4253+
resolved "https://registry.yarnpkg.com/netlify-auth-providers/-/netlify-auth-providers-1.0.0-alpha5.tgz#f0ce642fe5534f04a1d539ca847c907dd20819c8"
4254+
42514255
no-case@^2.2.0:
42524256
version "2.3.2"
42534257
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"

0 commit comments

Comments
 (0)