# POST error : 401 Unauthorized, authentication

**URL:** <https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440>\
**Category:** ionic-v3\
**Created:** [May 23, 2017, 2:01pm UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440 "2017-05-23T14:01:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMS\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@JMS\_Alex](https://forum.ionicframework.com/u/JMS_Alex)\
**Post date:** [May 23, 2017, 2:01pm UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440/1 "2017-05-23T14:01:34Z")

</div>

Hi,

I have a problem authenticating a user. In case of problems in the credentials (email and password), I display an error message with a toast. But since this morning, I have the error 401 Unauthorized that appears and so the toast no longer displays error messages. I do not understand where it comes from.

The console’s error

```auto

POST UrlAPI 401 (Unauthorized)
EXCEPTION: Response with status: 401 Unauthorized for URL: UrlAPI

```

And this is my code for the POST request

```auto
return this.http.post(link, data, options)
    .map((res: Response) => res.json())
    .subscribe((response) => {
            console.log("RESPONSE: ", response);
            if (response.status === 'ok'){
              this.UserData.setSessionId(response.session_id);
              console.log("SESS_ID SAVED", this.UserData.getSessionId());
              this.nav.setRoot(TabsPage);
             }
            else {
              let toast = this.toastCtrl.create( {
                  message: response.errors,
                  duration: 3000,
                  position: 'top'
              });
            toast.present();
          }
        });

```

Reponse Headers

> Access-Control-Allow-Origin:\*  
> Cache-Control:no-cache  
> Connection:Keep-Alive  
> Content-Length:57  
> Content-Type:application/json  
> Date:Tue, 23 May 2017 13:49:56 GMT  
> Keep-Alive:timeout=5, max=100  
> Server:Apache/2.4.10 (Debian)

Request Headers

```auto
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:16
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host: UrlAPI
Origin:http://localhost:8101
Referer:http://localhost:8101/?ionicplatform=ios&ionicstatusbarpadding=true
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 24, 2017, 3:09am UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440/2 "2017-05-24T03:09:03Z")

</div>

What are you intending to return from the “code for the POST request”?

---

<div class="post-metadata">

**Author:** ![JMS\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@JMS\_Alex](https://forum.ionicframework.com/u/JMS_Alex)\
**Post date:** [May 24, 2017, 9:36am UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440/3 "2017-05-24T09:36:51Z")

</div>

The API response, like that

```auto
{
  "status": "nok",
  "errors": [
    "Email or password incorrect"
  ]
}

```

On the console, the message is sent but it is blocked by error 401 and the toast is not displayed…

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 24, 2017, 7:42pm UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440/4 "2017-05-24T19:42:19Z")

</div>

> [@JMS\_Alex](#):
>
> The API response

That’s impossible, because it’s an asynchronous action. What you are currently returning is a subscription.

---

<div class="post-metadata">

**Author:** ![JMS\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@JMS\_Alex](https://forum.ionicframework.com/u/JMS_Alex)\
**Post date:** [May 25, 2017, 10:22am UTC](https://forum.ionicframework.com/t/post-error-401-unauthorized-authentication/91440/5 "2017-05-25T10:22:09Z")

</div>

Yes, I was wrong in my answer. I am a beginner with Angular and Ionic.  
An idea to help me?
