Skip to content

Commit d19a5a0

Browse files
WIP on master: d6924a6 Merge pull request #32 from jinsoolim/tutorial
2 parents d6924a6 + 854118c commit d19a5a0

File tree

6 files changed

+90
-86
lines changed

6 files changed

+90
-86
lines changed

__tests__/users.test.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const request = require('supertest');
2-
let server = 'https://reactype.herokuapp.com';
2+
//let server = 'https://reactype.herokuapp.com';
3+
let server = 'http://localhost:5000';
34
const isDev = process.env.NODE_ENV === 'development';
45
if (isDev) {
56
server = 'http://localhost:5000';
67
}
78

9+
console.log('is Dev====???', process.env.NODE_ENV);
10+
811
// tests user signup and login routes
912
describe('User authentication tests', () => {
1013
let num = Math.floor(Math.random() * 1000);
@@ -42,11 +45,11 @@ describe('User authentication tests', () => {
4245
it('responds with status 200 and json object on verified user login', () => {
4346
return request(server)
4447
.post('/login')
45-
.send({ username: 'reactyp3test', password: 'codesmith1!' })
48+
.send({ username: 'testing', password: 'codesmith1!' })
4649
.expect(200)
4750
.expect('Content-Type', /json/)
4851
.then((res) =>
49-
expect(res.body.sessionId).toEqual('5f0df0636678ba002ba43b88')
52+
expect(res.body.sessionId).toEqual('5fa99d1930e67b513c17ba61')
5053
);
5154
});
5255
it('responds with status 400 and json string on invalid user login', () => {
@@ -60,5 +63,22 @@ describe('User authentication tests', () => {
6063
});
6164
});
6265
});
63-
64-
describe('User Login Tests', () => {});
66+
describe('Github oauth tests', () => {
67+
describe('/github/callback?code=', () => {
68+
describe('GET', () => {
69+
it('responds with status 400 and error message if no code received', () => {
70+
return request(server)
71+
.get('/github/callback?code=')
72+
.expect(400)
73+
.then(res => {
74+
return expect(res.text).toEqual('\"Undefined or no code received from github.com\"');
75+
});
76+
});
77+
it('responds with status 400 if invalid code received', () => {
78+
return request(server)
79+
.get('/github/callback?code=123456')
80+
.expect(400)
81+
});
82+
});
83+
});
84+
});

app/electron/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ ipcMain.on('github', event => {
404404
zoomFactor: 1.0
405405
}
406406
});
407-
// const authUrl =
408-
// githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
409407
const authUrl =
410408
`${githubUrl}client_id=${process.env.GITHUB_ID}`;
411409
github.loadURL(authUrl);

app/src/components/login/SignIn.tsx

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { Component, useState, useEffect } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { LoginInt } from '../../interfaces/Interfaces';
33
import {
44
Link as RouteLink,
55
withRouter,
6-
useHistory,
76
RouteComponentProps
87
} from 'react-router-dom';
98
import { sessionIsCreated } from '../../helperFunctions/auth';
@@ -12,18 +11,14 @@ import Avatar from '@material-ui/core/Avatar';
1211
import Button from '@material-ui/core/Button';
1312
import CssBaseline from '@material-ui/core/CssBaseline';
1413
import TextField from '@material-ui/core/TextField';
15-
import FormControlLabel from '@material-ui/core/FormControlLabel';
16-
import Checkbox from '@material-ui/core/Checkbox';
17-
import Link from '@material-ui/core/Link';
1814
import Grid from '@material-ui/core/Grid';
1915
import Box from '@material-ui/core/Box';
2016
import Typography from '@material-ui/core/Typography';
21-
import { makeStyles, withStyles } from '@material-ui/core/styles';
17+
import { makeStyles } from '@material-ui/core/styles';
2218
import Container from '@material-ui/core/Container';
2319
import GitHubIcon from '@material-ui/icons/GitHub';
2420
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
25-
import { ipcRenderer } from 'electron';
26-
import { newUserIsCreated, isNewUser } from '../../helperFunctions/auth';
21+
import { newUserIsCreated } from '../../helperFunctions/auth';
2722
import randomPassword from '../../helperFunctions/randomPassword';
2823

2924
function Copyright() {
@@ -60,36 +55,6 @@ const useStyles = makeStyles(theme => ({
6055
borderColor: '#3EC1AC'
6156
}
6257
},
63-
facebookBtn: {
64-
backgroundColor: 'blue',
65-
color: 'white',
66-
// margin: theme.spacing(1, 0, 1),
67-
// fontSize: '20px',
68-
cursor: 'pointer',
69-
border: '0',
70-
outline: '0',
71-
position: 'relative',
72-
alignItems:' center',
73-
userSelect: 'none',
74-
verticalAlign: 'middle',
75-
justifyCcontent: 'center',
76-
textDecoration: 'none',
77-
padding: '6px 16px',
78-
fontSize: '0.875rem',
79-
minWidth: '64px',
80-
// box-sizing: border-box,
81-
transition: 'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
82-
// font-family: "Roboto", "Helvetica", "Arial", sans-serif,
83-
// fontWeight: '500',
84-
// line-height: 1.75,
85-
// border-radius: 4px,
86-
// letter-spacing: 0.02857em,
87-
// text-transform: uppercase,
88-
// color: rgba(0, 0, 0, 0.87),
89-
boxShadow: '0px 3px 1px -2px rgba(0,0,0,0.2),0px 2px 2px 0px rgba(0,0,0,0.14),0px 1px 5px 0px rgba(0,0,0,0.12)',
90-
width: '396px',
91-
// margin: 8px 0px 8px
92-
}
9358
}));
9459

9560
const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
@@ -258,32 +223,20 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
258223
color="default"
259224
className={classes.submit}
260225
onClick={() => {
261-
// messages the main proces to open new window for github oauth
262-
console.log('open github');
263-
// ipcRenderer.send('github-oauth', 'getToken');
264226
window.api.github();
265227
}}
266-
//onClick={handleGitHubOauth}
267228
>
268-
<GitHubIcon />
229+
<GitHubIcon />
269230
</Button>
270-
{/* <Button
271-
fullWidth
272-
variant="contained"
273-
color="primary"
274-
className={classes.submit}
275-
onClick={e => handleLoginGuest(e)}
276-
> */}
277231
<FacebookLogin
278232
appId={FBAPPID}
279233
autoLoad={false}
280234
fields="name, email, picture"
281235
callback={responseFacebook}
282236
icon="fa-facebook-square"
283-
cssClass={classBtn}
237+
cssClass={'oauth-btn'}
284238
textButton=' Login with Facebook'
285239
/>
286-
{/* </Button> */}
287240
<Button
288241
fullWidth
289242
variant="contained"

app/src/public/styles/style.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ body {
1616
font-weight: 400;
1717
overflow: hidden;
1818
}
19+
20+
/* span > button {
21+
background-color: #01d46d;
22+
width: 600px;
23+
} */
1924
/**************
2025
*
2126
* for Material React Table found in Add Child Props
@@ -408,3 +413,39 @@ h3 {
408413
height: 100%;
409414
width: 100%;
410415
}
416+
417+
.oauth-btn {
418+
-webkit-font-smoothing: antialiased;
419+
border: 0;
420+
display: inline-flex;
421+
outline: 0;
422+
position: relative;
423+
align-items: center;
424+
user-select: none;
425+
vertical-align: middle;
426+
justify-content: center;
427+
text-decoration: none;
428+
-webkit-appearance: none;
429+
-webkit-tap-highlight-color: transparent;
430+
padding: 6px 16px;
431+
font-size: 0.875rem;
432+
min-width: 64px;
433+
box-sizing: border-box;
434+
transition: background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
435+
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
436+
font-weight: 500;
437+
line-height: 1.75;
438+
border-radius: 4px;
439+
letter-spacing: 0.02857em;
440+
text-transform: uppercase;
441+
color: white;
442+
box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2),0px 2px 2px 0px rgba(0,0,0,0.14),0px 1px 5px 0px rgba(0,0,0,0.12);
443+
background-color:#4267B2;
444+
width: 396px;
445+
cursor: pointer;
446+
margin: 8px 0px 8px;
447+
}
448+
449+
.oauth-btn:hover {
450+
background-color: #4e76c7;
451+
}

server/controllers/sessionController.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ sessionController.startSession = (req, res, next) => {
6767

6868
//
6969
sessionController.gitHubResponse = (req, res, next) => {
70+
// console.log(req)
7071
const { code } = req.query;
72+
// console.log('code =>', code);
73+
if (!code) return next({
74+
log: 'Undefined or no code received from github.com',
75+
message: 'Undefined or no code received from github.com',
76+
status: 400
77+
});
7178
fetch(
7279
`https://github.com/login/oauth/access_token`,{
7380
method: 'POST',
@@ -105,7 +112,13 @@ sessionController.gitHubSendToken = (req, res, next) => {
105112
res.locals.signUpType = 'oauth';
106113
return next();
107114
})
108-
.catch(err => res.status(500).json({message: `${err.message} in gitHubSendToken`}))
115+
.catch(err =>{
116+
if (err.message === `Cannot read property 'email' of undefined`) {
117+
return res.status(400).json({message: `${err.message} in gitHubSendToken`});
118+
} else {
119+
return res.status(500).json({message: `${err.message} in gitHubSendToken`});
120+
}
121+
});
109122
}
110123

111124
// creates a session when logging in with github

server/server.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const express = require('express');
2-
// const https = require('https');
32
const fs = require('fs');
43
const path = require('path');
5-
const passport = require('passport');
6-
require('./passport-setup');
4+
// const passport = require('passport');
5+
// require('./passport-setup');
76
const bodyParser = require('body-parser');
87
const cookieParser = require('cookie-parser');
98
const cors = require('cors');
@@ -18,10 +17,9 @@ const isDev = process.env.NODE_ENV === 'development';
1817

1918
console.log('PORT is ', PORT);
2019

21-
// handle parsing request body
2220
app.use(express.json());
23-
// cookie parser
2421
app.use(cookieParser());
22+
2523
// enable cors
2624
// options: origin: allows from localhost when in dev or the app://rse when using prod, credentials: allows credentials header from origin (needed to send cookies)
2725
app.use(
@@ -36,23 +34,8 @@ app.use(
3634
// subsequent logins seem to be working fine, however
3735

3836
// initializes passport and passport sessions
39-
app.use(passport.initialize());
40-
app.use(passport.session());
41-
42-
// routes for initial github oauth and callback
43-
app.get(
44-
'/github',
45-
(req, res) => {
46-
console.log('git hub');
47-
res.redirect(`https://github.com/login/oauth/authorize?client_id=${clientId}`);
48-
});
49-
50-
// app.post(
51-
// '/facebook',
52-
// userController.doesUserExist,
53-
// (req, res) => {
54-
// return res.status(200).json({ userStatus: res.locals.userExists });
55-
// });
37+
// app.use(passport.initialize());
38+
// app.use(passport.session());
5639

5740
app.get(
5841
'/github/callback',
@@ -63,16 +46,12 @@ app.get(
6346
cookieController.setSSIDCookie,
6447
sessionController.startSession,
6548
(req, res) => {
66-
// TODO - figure out how to send a response that closes window
6749
if (isDev) {
6850
return res.status(200).redirect(`http://localhost:8080?=${res.locals.ssid}`);
6951
} else {
7052
return res.status(200).redirect('app://rse');
7153
}
7254
}
73-
// (req, res) => {
74-
// return res.status(200).json({ sessionId: res.locals.ssid });
75-
// }
7655
);
7756

7857
app.post(

0 commit comments

Comments
 (0)