Advertisement
EntropyStarRover

auth service

Jun 21st, 2021
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const User=require('../models/User');
  2.  
  3. async function createUser(username, hashedPasword){
  4. //adapt to rewuirements
  5. const user=new User({
  6. username,
  7. hashedPasword
  8. });
  9.  
  10. await user.save();
  11. return user;
  12. }
  13.  
  14.  
  15. async function getUserByUsername(username){
  16. const pattern= new RegExp(`^${username}$`,'i');
  17. const user=await User.findOne({username:{$regex: pattern }});
  18. return user;
  19. }
  20.  
  21. module.exports={
  22. createUser,
  23. getUserByUsername
  24. }
Advertisement
RAW Paste Data Copied
Advertisement