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

ft: implement user logout feature #67

Merged
merged 1 commit into from
May 7, 2024
Merged

ft: implement user logout feature #67

merged 1 commit into from
May 7, 2024

Conversation

Ndevu12
Copy link
Contributor

@Ndevu12 Ndevu12 commented May 6, 2024

What does this PR do?

This pull request aims to add feature that enables a user to logout

Description of Task to be completed?

The task completed in this pull request includes:

  • check if a user has access or logged in
  • access and clear user's access token from cookie
  • provide success message for success and error message else

How should this be manually tested?

To manually test all the changes made in this pull request, follow these steps:

git clone -b ft-logout https://github.com/atlp-rwanda/knights-ecomm-be.git
cd knights-ecomm-be
npm i
npm run dev

@Ndevu12 Ndevu12 requested review from MC-Knight, elijahladdie, maxCastro1 and faid-terence and removed request for MC-Knight and elijahladdie May 6, 2024 11:53
@Ndevu12 Ndevu12 self-assigned this May 6, 2024
@Ndevu12 Ndevu12 added the Ready for reviews Pull request is ready for review label May 6, 2024
@Ndevu12 Ndevu12 added this to the Authentication and RBAC milestone May 6, 2024
@Ndevu12 Ndevu12 linked an issue May 6, 2024 that may be closed by this pull request
4 tasks
@Ndevu12 Ndevu12 changed the title Ft-implement user logout feature ft-implement user logout feature May 6, 2024
@Ndevu12 Ndevu12 changed the title ft-implement user logout feature ft: implement user logout feature May 6, 2024
@Ndevu12 Ndevu12 force-pushed the ft-logout branch 3 times, most recently from 5f07546 to 5ea5e8d Compare May 7, 2024 11:10
@coveralls
Copy link

coveralls commented May 7, 2024

Pull Request Test Coverage Report for Build 8985631303

Details

  • 44 of 65 (67.69%) changed or added relevant lines in 9 files are covered.
  • 4 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.6%) to 75.489%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/controllers/authController.ts 7 8 87.5%
src/middlewares/isValid.ts 3 4 75.0%
src/services/userServices/userLoginService.ts 0 3 0.0%
src/services/userServices/logoutServices.ts 6 10 60.0%
src/services/userServices/userPasswordResetService.ts 13 25 52.0%
Files with Coverage Reduction New Missed Lines %
src/utils/sendMail.ts 1 84.62%
src/middlewares/isValid.ts 1 54.17%
src/services/userServices/userLoginService.ts 1 47.83%
src/services/userServices/userSendOTPEmail.ts 1 88.89%
Totals Coverage Status
Change from base Build 8982551896: -0.6%
Covered Lines: 481
Relevant Lines: 593

💛 - Coveralls

Comment on lines 13 to 33
const { email } = req.body;

if (!email) {
console.log('No email address provided');
return res.status(400).json({ status: 'error', message: 'Please provide an email' });
}

const userRepository = getRepository(User);
const user = await userRepository.findOneBy({ email });

if (!user) {
console.log('User not found');
return res.status(404).json({ status: 'error', message: 'Incorrect email' });
}

const otpCode = await start2FAProcess(user.email);
if (!otpCode) throw new Error('Error generating OTP');
const OTPEmailcontent = otpTemplate(user.firstName, otpCode.toString());
if (!OTPEmailcontent) throw new Error('Error generating OTP email content');
await sendOTPEmail('Login OTP', user.email, OTPEmailcontent);
if (process.env.APP_ENV !== 'test') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove consoles please

Comment on lines 21 to 26

try {
const info = await transporter.sendMail(mailOptions);
console.log('Message sent: %s', info.messageId);
} catch (error) {
console.log('Error occurred while sending email', error);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console.log here as well

@Ndevu12 Ndevu12 requested review from a team and removed request for MC-Knight May 7, 2024 15:35
Copy link
Collaborator

@faid-terence faid-terence left a comment

Choose a reason for hiding this comment

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

Nice Work @Ndevu12 !

@faid-terence faid-terence merged commit a8de772 into develop May 7, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for reviews Pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: User Logout
5 participants