Cant output the status 422 message in console - reactjs

here is the screenshot of the output I am using mongodb. created a signup page and now checking whether a user already exists
const existingUser = await db.collection('users').findOne({ email: email });
if (existingUser) {
res.status(422).json({ message: 'User already exists !' });
client.close();
return;
}
Error message : auth-form.js:7 POST http://localhost:3000/api/auth/signup 422 (Unprocessable Entity)
I should expect this error but i also want to show the text 'User already exists !' in the console

Related

How to update the password of a Supabase user on a NextJs project?

I'm facing an issue updating a password for a supabase user on a BlitzJs (NextJs) project.
Basically, I have a reset password method that works perfectly. First I send an email with a reset link, that opens a page where the user can update his password like so:
const { error, data } = await supabase.auth.api.updateUser(token, { password: password.trim() })
the token being the one in the url, provided in the email link.
So far, so good, but when I try to update the password for a logged in user, using the exact same method supabase.auth.api.updateUser, it fails to find the user;
The difference is the token is the session.access_token
So I've tried to use the supabase.auth.api.updateUserById method, but it gives me another error: { message: 'User not allowed', status: 401 }
Any ideas? I feel the supabase docs about this is not very clear, and probably outdated as it doesn't show all the available methods :/
Update password for authenticated user.
const { user, error } = await supabase.auth.update({password: 'new password'})
For more informations check: Supabase references

Error: Argument error: username and password are required unless use_unauthenticated is set

I'm attempting to use STT service with the iam apikey.
If I set the IAM credentials like the documentation shows (below) I get the error: username and password are required unless use_unauthenticated is set
let speech_to_text = new SpeechToTextV1({
iam_apikey: STT_credentials.apikey,
iam_url: STT_credentials.url
});
If I pass the use_anauthenticated value I get a 401 response:
let speech_to_text = new SpeechToTextV1({
iam_apikey: STT_credentials.apikey,
iam_url: STT_credentials.url,
use_unauthenticated: true
});
response:
Error! Code:401 Type: undefined Message: Unauthorized
If I look at the file in the error:
/Users/jward/Desktop/speech_lab_assets/STT/node_mod
ules/watson-developer-cloud/lib/base_service.js:73:13
I see that it will throw an error if there is no username/password param:
if (!options.use_unauthenticated) {
if (!options.username || !options.password) {
throw new Error('Argument error: username and password are required unless use_unauthenticated is set');
}
How am I supposed to use IAM if the username/password is a requirement of the watson-developer-cloud tooling? Is this an issue with the node module or am I doing something wrong?
I am using watson-developer-cloud#2.42.0
The endpoint is specified as url and not iam_url as you have it.
This works for me -
const STTV1 = require('watson-developer-cloud/speech-to-text/v1');
let sttService = new STTV1({
url: url,
iam_apikey = apikey
});

Chrome extension issue in block-chain transaction

Basically I want a chrome extension which takes data from block-chain and display in browser content-script also when user click on that data one transaction happen which will increase the count in block-chain.
I am able to retrieve data from block-chain please check the below code.
async componentDidMount(){
const ads = await advertiserAbi.methods
.getSpecificAdvertiserDetail(
"any address").call();
this.setState({ads});
}
But the problem is coming in performing transaction. Please check the below code.
async onSubmitForUpdate() {
console.log("Hello");
await userAbi.methods
.setStatistics("any address")
.send({
from: "any address"
});
}
Below is the error which I am getting.
POST https://rinkeby.infura.io/<--specific address--> 405 ()
Uncaught (in promise) Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (content.js:108391)
at XMLHttpRequest.request.onreadystatechange (content.js:119211)

ANgular js show always email successfully sent although not sent

I want to send mail to user i succeeded for that using spring boot and angular but i have a problem is that in my console always show me the message that my mail: succeesfuly sent: as mail is sent to user:
this is my angular js controller.js:
$scope.sentMail = function() { var data = new FormData();var mail= $scope.account.mail;
console.log('test 1 :', $scope.account.mail);
console.log("sent mail");
$http.post(_contextPath + '/sentEmail',mail).then(Failure)
.catch(Success);
function Success(success) {
// console.log(response.data);
console.log(' email is successfully sent:', $scope.account.mail);
}
function Failure(error) {
console.log('A problem occurred while sending an email.');
}
}
this is my controller.java:
#RequestMapping(value = "/sentEmail", method = RequestMethod.POST, headers = "Accept=application/json")
public ModelAndView processForgotPasswordForm(ModelAndView modelAndView, HttpServletRequest request, #RequestBody String mail) throws MessagingException
{
System.out.println("print");
User optional= usersService.findByEmail(mail);
if((optional== null))
{
modelAndView.addObject("errorMessage", "We didn't find an account for that e-mail address.");
}
else{
optional.setResetToken(UUID.randomUUID().toString());
usersService.save(optional);
String appUrl = request.getScheme() + "://" + request.getServerName();
SimpleMailMessage passwordResetEmail = new SimpleMailMessage();
passwordResetEmail.setFrom("test#test.com");
passwordResetEmail.setTo(optional.getUserEmail());
passwordResetEmail.setSubject("Password Reset Request");
passwordResetEmail.setText("Hello "+ optional.getUserFirstname()+" "+ optional.getUserLastname()+", \n \n You recently request to reset your password for rotana platform. Please click the link below to reset it : \n \n"+ appUrl +":8080/neorchaWEBPlatform"+ "/reset?token=" + optional.getResetToken()
+"\n \n if you did not request a password reset, please ignore email or reply to let us know.\n \n Thanks, \n \n Rotana Group \n \n P.S. We also love hearing from you and helping you with any issues you have. Please reply to this email if you want to ask a question.");
modelAndView.addObject("ResetMessage", "An e-mail has been sent to " + optional.getUserEmail());
emailService.sendEmail(passwordResetEmail);
}
modelAndView.setViewName("forgotPassword");
return modelAndView;
}
any help,thanks in advance.
.then will handle 'successful' responses. .catch will handle any errors in your success or error functions. You don't have an error function registered. I believe your code should be setup something like this:
$http.post(_contextPath + '/sentEmail',mail).then(Success, Failure)
.catch(UnexpectedError);
function Success(success) {
// console.log(response.data);
console.log(' email is successfully sent:', $scope.account.mail);
}
function Failure(error) {
console.log('A problem occurred while sending an email.');
}
function UnexpectedError(error) {
console.log('Something unexpected happened in Success() or Failure()');
}
The success and error callbacks look at the status being returned by your server. From the Angular documentation:
A response status code between 200 and 299 is considered a success
status and will result in the success callback being called. Any
response status code outside of that range is considered an error
status and will result in the error callback being called. Also,
status codes less than -1 are normalized to zero. -1 usually means the
request was aborted, e.g. using a config.timeout. Note that if the
response is a redirect, XMLHttpRequest will transparently follow it,
meaning that the outcome (success or error) will be determined by the
final response status code.
see: https://docs.angularjs.org/api/ng/service/$http

Debugging CakeEmail, msg sent but not received

I'm using CakePHP 2.1.1 and trying to send a simple email with form data. This is the code I have in my controller:
App::uses('CakeEmail', 'Network/Email');
try {
$Email = new CakeEmail();
$Email->from(array('support#pcn.com' => 'PC'));
$Email->to('me#gmail.com');
$Email->subject('New Registration');
if ( $Email->send(serialize($formData)) )
$this->set('email', 'Success');
else
$this->set('email', 'Failure without Exception');
}
catch ( Exception $e ) {
$this->set('email', 'Failure with Exception );
}
When I print out the value of 'email' in my view, it is always 'Success', but I never receive the email (ive checked the spam folder). There are no email related issues in the error log. How do I debug this problem and get the email to send properly?

Resources