Back

Cannot handle error on auth session start

  • 0
  • Web
Isak
30 Jun, 2024, 07:37

When I auth the user and a session is already initialized, I get this response in the console

TypeScript
{
    "message": "Creation of a session is prohibited when a session is active.",
    "code": 401,
    "type": "user_session_already_exists",
    "version": "1.5.7"
}

But when I console.log the response, it doesn't log. How am I supposed to handle the issue if I cannot get the error why the session can't start?

TypeScript
let session = await appwrite.account.createEmailPasswordSession(username, password);
console.log("session", session)
TL;DR
Developers are unable to handle the error on the auth session start. The user is trying to log out to log in again but the error codes are not returning, and they wish to get the response instead. The user is not able to see the 'type' error code needed for handling errors. **Solution:** The developer should log the error in the `catch` block of the promise to see the exact 'type' error code. This way they can handle the issue and take the necessary steps.
CodingXeer01
30 Jun, 2024, 07:44
TypeScript
session.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});
Isak
30 Jun, 2024, 07:46
TypeScript
let promise = appwrite.account.createEmailPasswordSession(username, password);

promise.then(function (response) {
    console.log("response", response); // Success
}, function (error) {
    console.log("error", error); // Failure
});

The error codes etc isn't printed, I'm looking to get the response

Isak
30 Jun, 2024, 07:46
CodingXeer01
30 Jun, 2024, 07:50

it means you are already logged in, you have to be log out to login again

Isak
30 Jun, 2024, 07:55

I know, but I want to handle the error

Isak
30 Jun, 2024, 07:55

I want to get the response code ”type”

Isak
30 Jun, 2024, 07:55

Im only getting the message

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