Skip to content
Advertisement

How to know if the input is Email or username

I’m trying to let the user sign in using email OR username, I already implemented the backend and it’s working fine using Postman, but I didn’t know how to implement it in the frontend,

Login.jsx:

JavaScript

My question is how to let the INPUT knows if the user is typing a username or an email and then act accordingly, or is there any easy way to get this done?

Backend Auth.js:

JavaScript

Advertisement

Answer

So i implemented it on the back-end, I figured out that I don’t have to check if the input is username or an email all I have to do is using $or in the User.findOne it worked like charm here is the code in case of somebody finds it helpful

JavaScript

and in the front-end:

JavaScript

and for the input:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement