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

#23187419173 - fx:fixed Two Factor Authentication for Sellers #43

Merged
merged 1 commit into from
May 4, 2024

Conversation

soleil00
Copy link
Collaborator

@soleil00 soleil00 commented May 3, 2024

What does this PR do?

This PR sets up Two Factor Authentication for Sellers

Description of Task to be completed?

-GIVEN there is a request to log in a user to the website
WHEN 2FA is enabled on the particular user
THEN Further request for a 2FA token should be requested and once the token is received and validated, the user is allowed to log in.

How should this be manually tested?

  1. checkout this branch and run app
  2. regiter new user and modify user role to seller
  3. then login with email and password
  4. there u will see magic happen u will get message that verification token has been sent to ur email with verification link
  5. go there open email and copy token and send them in req.body to specified endpoint in body /api/v1/users/2fa-verify

pivotal tracker id ----> #23187419173

Screenshots

Screenshot 2024-05-03 at 19 34 57 Screenshot 2024-05-03 at 20 08 45 Screenshot 2024-05-03 at 20 09 04

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2024

Codecov Report

Attention: Patch coverage is 48.88889% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 78.35%. Comparing base (4e270ea) to head (eecc41f).

Files Patch % Lines
src/controllers/userControllers.ts 30.30% 22 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #43      +/-   ##
==========================================
+ Coverage   78.30%   78.35%   +0.04%     
==========================================
  Files          56       55       -1     
  Lines         899      901       +2     
  Branches      124      128       +4     
==========================================
+ Hits          704      706       +2     
+ Misses        195      192       -3     
- Partials        0        3       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 64 to 67
const link =
process.env.NODE_ENV !== "production"
? `http://localhost:${env.port}/api/v1/users/2fa-verify/${token}`
: `https://eagles-ec-be-development.onrender.com/api/v1/users/2fa-verify/${token}`;
Copy link
Member

Choose a reason for hiding this comment

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

don't hardcode this things, create .env for url, this this will be called from front-end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeap

Comment on lines 27 to +28
userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword);
userRoutes.post("/2fa-verify", isTokenFound, tokenVerification);
userRoutes.get("/2fa-verify/:token",tokenVerification);
Copy link
Member

Choose a reason for hiding this comment

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

are you verifying from get method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oooh I missed this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

again for that get its verification link that user click and u can't use post using link since it will be opened directly in browser
perhaps when we put fronted url its possibl

Copy link
Member

Choose a reason for hiding this comment

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

this will be handled from front-end tha means link will be front-end link, but leave it for now


export const sendEmailService = async (user: IUser, subject: string, template: any, token: number) => {
export const sendEmailService = async (user: IUser, subject: string, template: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

do you think this function can be re-used , why that user can you put email instead whole user object

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes its reusable i removed token since token doesn't have naything todo with that sendEmailService, token or any other related info has be passed as argument in emailTemplate not in service

Copy link
Member

Choose a reason for hiding this comment

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

also pass email to send to not whole user

@@ -86,6 +86,7 @@
"express": "^4.19.2",
"express-session": "^1.18.0",
"husky": "^9.0.11",
"ioredis": "^5.4.1",
Copy link
Member

Choose a reason for hiding this comment

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

are you using this?

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 was about to use it but realy i'm not using it currently, since token don't last long(10min) i decided not to blacklist verification token s

Copy link
Member

Choose a reason for hiding this comment

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

remove it then

@teerenzo teerenzo merged commit 351bd7f into dev May 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants