-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First merge if Backend branch vs v.2.x #22
base: v.2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix changes, comment code and resend PR
server/queries/basic-queries.js
Outdated
User.findOne({ githubId: profile.id }).then((errors, currentUser) => { | ||
if (currentUser) { | ||
currentUser.overwrite({ token: accessToken }).save(); | ||
response.status(201).send(rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not declaring rows here. Remove
…e if Backend branch vs v.2.x #22
… the API and modified Github Strategy to save the new token every time the api returns a new authentication code
First of all, I'd like to apologize for the magnitude of this PR. It is totally unacceptable and I will do my best to avoid this kind of situation next time. What does this PR include?Frontend (/client/src)
Backend (/server)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to review everything but since it's a quite long PR I could miss some things 😅
This is an amazing job and this will set up a good base in order to move forward with the gitRank v2. So excited for that! 👏 💯
BrowserRouter as Switch, | ||
Route, | ||
BrowserRouter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're importing BrowserRouter
twice. Maybe what we wanted is something like the basic example of React Router
In that case, we should modify:
BrowserRouter as Switch, | |
Route, | |
BrowserRouter, | |
Switch, | |
Route, | |
BrowserRouter, |
const [token, setToken] = useState(''); | ||
const [username, setUsername] = useState(''); | ||
const [offline, setOffline] = useState(!navigator.onLine); | ||
const [token, setToken] = useState(localStorage.getItem('token') || ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see a very common pattern where you want to Load/Save state from the local storage and set it in the state. I'd think about having a custom hook for that. What do you think?
/* the user can access the app through two different options: | ||
1. indicating username and token manually. In the case of GitHub Enterprise the user also needs to indicate the endpoint. | ||
2. Github authentication */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a very common practice to use block comment like this:
/* the user can access the app through two different options: | |
1. indicating username and token manually. In the case of GitHub Enterprise the user also needs to indicate the endpoint. | |
2. Github authentication */ | |
/** | |
* the user can access the app through two different options: | |
* 1. indicating username and token manually. In the case of GitHub Enterprise the user also needs to indicate the endpoint. | |
* 2. Github authentication | |
**/ |
But this is totally up to you :)
const userId = getIdFromLocation(); | ||
if (userId) { | ||
// if there's id, we need to look for the token stored in the ddbb | ||
fetch(`http://localhost:8080/users/${userId}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about using environment variables to set the API_URL? I think it could be a good step to upload your code without needing to app another PR to change this :)
fetch(`http://localhost:8080/users/${userId}`) | |
fetch(`${process.env.API_URL}/users/${userId}`) |
.then(res => { | ||
return res.text(); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use arrow return syntax instead? I think we can save a couple of lines :)
.then(res => { | |
return res.text(); | |
}) | |
.then(res => res.text()) |
@@ -0,0 +1,33 @@ | |||
{ | |||
"name": "server", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"name": "server", | |
"name": "gitRank API", |
router.get('/users', queries.getUsers); | ||
router.get('/users/:id', queries.getUserById); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be private routes. Otherwise, the server will be accessible.
/* callback route for github to redirect to | ||
hand control to passport to use code to grab profile info */ | ||
router.get('/github/redirect', passport.authenticate('github'), (req, res) => { | ||
res.redirect(`http://localhost:3000/dashboard?id=${req.user.githubId}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res.redirect(`http://localhost:3000/dashboard?id=${req.user.githubId}`); | |
res.redirect(`${process.env.BASE_URL}/dashboard?id=${req.user.githubId}`); |
const users = await User.find(); | ||
response.status(200).send(users); | ||
} catch (error) { | ||
response.status(500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to send the error message to the response in order to give context to the API client.
response.status(500); | |
response.status(500).send(error); |
const user = await User.findOne({ githubId: id }); | ||
response.status(200).send(user); | ||
} else { | ||
response.status(204); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.status(204); | |
response.status(204).send(`User with id ${id} not found`); |
This pull request aims to clean up all the commits and code added in the last couple of days, before opening a formal pull request.