Skip to content
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

Implement Passport.js Local Strategy #696

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

briansegura15
Copy link
Collaborator

This commit for #617 integrates Passport's Local Strategy for user authentication.
The strategy has been set up to use email as the username field. If the email is not found or the password is incorrect, error messages are returned.
Was not sure how to implement tests on Users because users do not exist yet.
Co-authored-by: KonnyGuo [email protected]

Copy link
Collaborator

@DietBepis1 DietBepis1 left a comment

Choose a reason for hiding this comment

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

How should we handle merging this story, #617 , and #644?

Or should we combine them into one new branch so we can test the whole thing at once? That feels like the right approach to me personally, but I would like your thoughts.

@@ -8,35 +8,35 @@ on:
pull_request:
types: [opened]
branches:
- main
- main
Copy link
Collaborator

Choose a reason for hiding this comment

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

The oldest comment in the book: Rebase to remove these 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wait were they literally the oldest comments in the codebase? lol! Rebased ✅

},
async (email, password, done) => {
try {
const user = await User.findOne({
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will have to update this config to use Admins. For password validation, check out server/lib/encrypt after you rebase this. That will have the methods you need.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now that the Admin model exists and has been implemented, the mock User model has been removed and config updated. Password validation now being handled by the code in server/lib/encrypt

})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findByPk(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 think you can just use Admin.query().findById() now.
https://vincit.github.io/objection.js/api/query-builder/find-methods.html#findbyid

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cleaned up this code to use .query().findById(id) instead of .findByPk(id)

Copy link
Collaborator Author

@briansegura15 briansegura15 left a comment

Choose a reason for hiding this comment

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

All changes addressed 👍

@@ -8,35 +8,35 @@ on:
pull_request:
types: [opened]
branches:
- main
- main
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wait were they literally the oldest comments in the codebase? lol! Rebased ✅

},
async (email, password, done) => {
try {
const user = await User.findOne({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now that the Admin model exists and has been implemented, the mock User model has been removed and config updated. Password validation now being handled by the code in server/lib/encrypt

})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findByPk(id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cleaned up this code to use .query().findById(id) instead of .findByPk(id)

@briansegura15 briansegura15 force-pushed the passport-local-strategy-BS branch from 83d2c7f to 46a3bb4 Compare January 2, 2024 17:57
@briansegura15
Copy link
Collaborator Author

As for your first question, I agree that we should merge these couple branches into 1 since it originally was 1 Issue, but we broke it down with Konny to work on it separately.

@briansegura15 briansegura15 force-pushed the passport-local-strategy-BS branch from 46a3bb4 to 57d99e0 Compare January 3, 2024 01:57
This commit integrates Passport's Local Strategy for user authentication. The strategy has been set up to use email as the username field. If the email is not found or the password is incorrect, error messages are returned. Co-authored-by: KonnyGuo [email protected]

Implement Passport.js Local Strategy
    This is the second increment after changes were requested in the review. This commit integrates Passport's Local Strategy for user authentication. The strategy has been set up to use email as the username field. If the email is not found or the password is incorrect, error messages are returned. Co-authored-by: KonnyGuo [email protected]

Revised Implementation of Passport.js Local Strategy
    This is the second increment after changes were requested in the review. This commit integrates Passport's Local Strategy for user authentication. The strategy has been set up to use email as the username field. If the email is not found or the password is incorrect, error messages are returned. Co-authored-by: KonnyGuo [email protected]
@DietBepis1 DietBepis1 force-pushed the passport-local-strategy-BS branch from 57d99e0 to d1745c3 Compare January 14, 2024 16:10
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.

2 participants