Skip to content

Conversation

@ebrahimbeiati
Copy link
Collaborator

Implemented OAuth 2.0 GitHub authentication flow

@bkarimii
Copy link
Owner

The PR structure doesn't follow the project rules. please fix it and add description to your PR.

Copy link
Collaborator

@oliverlloyd oliverlloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of great work here, well done!

Would it be possible to update the description to explain what the changes are and why each one is needed. It would be really useful to have an overview for things

It would also be great to see some more comments in the code explaining what the different functions and steps are doing 🙏

}
}, [userData]);

const contextValue = useMemo(() => ({ userData, setUserData }), [userData]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use useMemo here? This doesn't look like an expensive calculation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​I use useMemo to ensure that the contextValue object passed to the Context Provider maintains the same reference between renders unless userData or setUserData change. This helps prevent unnecessary re-renders of components consuming the context, optimizing performance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get this answer from AI? :)

I don't see any benefit to useMemo here. Does it work if you remove it?

return false;
}
setFileList((prevList) => [...prevList, file]);
return true; // Allow the file to be added to the list
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for deleting this comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one :)

// Allow the file to be added to the list

I noticed it was removed and wondered why 🤷

Copy link
Collaborator

@oliverlloyd oliverlloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the PR description please to explain what this solution is doing and why it is doing it? 🙏

import { SubscriptionLogo } from "../components/SubscriptionLogo";
import { ThemedButton } from "../components/ThemedButton";

const CLIENT_ID = import.meta.env.VITE_GITHUB_CLIENT_ID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this line is meant to be doing? I don't think this will work


const handleGitHubLogin = () => {
window.location.assign(
`https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client_id is public (it is used in the url so everyone can see it) so it does not need to be kept secret and can just be entered in the code here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we review the functions in this file to add logger.info and logger.error statements so that we have data in our logs about what is happening here

If we don't log errors or info about what is happening, we won't be able to debug problems.

Note. We should try to write detailed logs but we don't want to write any sensitve information to the log such as ids, passwords or email address

const userData = await response.json();
req.user = userData;
next();
} catch (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere where we have an error we should capture this with logger.error

Comment on lines +59 to +60
module.exports.CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET;
module.exports.CLIENT_ID = process.env.GITHUB_CLIENT_ID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct way to include these values. We already have an existing module.exports line

Better would be to have

github: {
  GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
  // etc.
}

and add this to the extsing config object

Comment on lines +7 to +9
import AuthCallback from "./pages/AuthCallback.jsx";
import { ConfirmationPage } from "./pages/ConfirmationPage.jsx";
import Dashboard from "./pages/Dashboard.jsx";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should also be named imports. It's good to keep things consistent 🙏

Comment on lines +1 to +2
import bodyParser from "body-parser";
import cors from "cors";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for including these?

It's always good to comment your own PRs with explanations for things so it's clear to reviewers why things area happening

}
}, [userData]);

const contextValue = useMemo(() => ({ userData, setUserData }), [userData]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get this answer from AI? :)

I don't see any benefit to useMemo here. Does it work if you remove it?

@textbook
Copy link

textbook commented Apr 12, 2025

Please don't "roll your own" security. Use existing, tested tools like Passport.

There's an example of this in use in CYF/tech-products-demo, where it's all handled server-side so the client can just have a vanilla link to start the process:

              <a href="/api/auth/login">Log In</a>

@ebrahimbeiati ebrahimbeiati changed the title Add GitHub Authentication 91- Add GitHub Authentication- client side - Ebrahim Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants