Sunday 28 June 2020

Response from api appears in the console but does not work in my function

Hello,So I have an api for testing fake user accounts with my auth code. I get the response and first console.log it and so far it has worked. But, more importantly, I need it to pass to my authenticate function. I'm not getting any errors for undefined or null. Additionally, I know the code works because I've tested it before with static json files. BTW I'm using the centra package for making http requests with my api.const c = require('centra');module.exports = {authenticate};async function authenticate({ username, password }) {c(process.env.API).send().then(response => response.json()).then(response => {console.log(response)const user = response.find(u => u.username === username && u.password === password);  if (user) {const { password, ...userWithoutPassword } = user;return userWithoutPassword;     }   }); }Is there any issue with my authenticate function? Thanks!!

Submitted June 28, 2020 at 07:14PM by LGm17

No comments:

Post a Comment