Back

The CreateEmailSession() function do not return a promise on Node js server

  • 0
  • Web
tdnshah
26 Mar, 2023, 12:31

As per the document and example code give here https://appwrite.io/docs/client/account?sdk=web-default#accountCreateEmailSession I was expecting a promise to be returned, it was returning a promise when I tried via client side request, but when I shifted the code to the server side execution, I am not getting a response as a promise indeed for a valid a user the response if a session object and for invalid user the SDK throws an error.

Seems a little strange to me how come the response type changes upon where it is implemented?

Problem: Due to this I am unable to show an exactly error like wmail is invalid or password is incorrect to the user, indeed what appwrite does is throws and exception if the username or password is invvalid

Can any one help with this ?

TL;DR
The user is having an issue where the `createEmailSession()` function on their Node.js server is not returning a promise as expected. Another user suggests removing the use of the `await` keyword in the code to fix the issue. The user is also experiencing a problem where they cannot show an error message for invalid credentials because the SDK throws an exception instead. No solution is provided for this second issue.
Binyamin
26 Mar, 2023, 13:41

Can you share the code?

tdnshah
26 Mar, 2023, 14:05
TypeScript
tdnshah
26 Mar, 2023, 14:05

here it is, its little messy please bare with it 😛

Binyamin
26 Mar, 2023, 14:09

If you're using the keyword await then you will get the results and the promise. so change from this

TypeScript
      let promise = await account.createEmailSession(userName, passWord);
      promise.then(function (response) {

To this,

TypeScript
     let promise = account.createEmailSession(userName, passWord);
      promise.then(function (response) {

and then you'll get back the promise.

tdnshah
26 Mar, 2023, 14:15

Ohh got it

tdnshah
26 Mar, 2023, 14:19

@Binyamin thanks a lot this was a silly one my bad, I was not having the proper understanding of how promise works .

Binyamin
26 Mar, 2023, 14:25

👍 Sure thing, seems just fine

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more