# C8Y application requiring a second login

**URL:** <https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [January 26, 2024, 4:56pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763 "2024-01-26T16:56:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 26, 2024, 4:56pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/1 "2024-01-26T16:56:32Z")

</div>

I recently changed my user password for my C8Y account, and since then one of my applications is requiring me to authenticate a second time.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/b/6/b620fb7202b5ad1581f866de66db23395aec6d98.png)

The only problem is that when I add my credentials, the application returns a 401 error.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/e/3/e341125f86a2eb1566f9d1ad9eceae43f2adb1ac.png)

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [January 26, 2024, 6:23pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/2 "2024-01-26T18:23:04Z")

</div>

Hi @luclib,

Do you have some more details to when this issue occurs?  
Is it happening during local development or when your application is actually deployed to your cloud environment?  
Does it only happen with your custom developed applications or also in the default apps?  
Is it always a specific request that fails?

It seems you are calling a custom endpoint `/service/templates-basic/api/ErrorLogsAnalysis` from a microservice here.  
Can you provide the code snipped of the UI that makes this call?

Regards,  
Tristan

---

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 26, 2024, 6:45pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/3 "2024-01-26T18:45:09Z")

</div>

Hi Tristan,

So, the above screens were taken with the apps already uploaded onto the Cumulocity tenant.

I tried with the version on my localhost and, this time, it did not requesting additional authentication but it is still returning error messages.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/8/5/85c4f1da34bfa774863a36a0b43089c654e4d0cd.png)

Here is the code snippet

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/e/e/ee845ac6187af4e7eee0f21a3af19746009d65e4.png)

---

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 26, 2024, 6:46pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/4 "2024-01-26T18:46:08Z")

</div>

Could it have something to do with my login settings?

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [January 29, 2024, 10:05am UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/5 "2024-01-29T10:05:00Z")

</div>

Hi Lucas,

my guess it that you are not adding the correct request headers to your `http.post` call.  
If you would use the `FetchClient` that is part of `@c8y/client` you would have all the required headers attached to your request.

Regards,  
Tristan

---

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 29, 2024, 4:43pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/6 "2024-01-29T16:43:10Z")

</div>

Hi Tristan,

I tried refactoring my code as follows:

```auto
 const options: IFetchOptions = {
            method: 'POST',
            headers: { 'Authorization': environment.postApiKey },
            body: formData
};

 const response = await this.fetchClient.fetch(environment.postUrl, options);

 const res = await response.json();
  
 this.repairStrategyList = res['repairStrategyList'];
 this.parts = res['parts'];
 let logs = res['reponseObject'];

```

Now I am getting a different error type:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/5/0/50314e99d59bdbcc70127099a82c59b144934fe4.png)

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [January 29, 2024, 7:00pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/7 "2024-01-29T19:00:19Z")

</div>

Can you also show the `environment.postUrl` and `formData` parts?

---

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 29, 2024, 7:09pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/8 "2024-01-29T19:09:31Z")

</div>

Of course.

Here is the formData part:

```auto
const formData = new FormData(); 
        for(let file of this.fileList){
            formData.append('file', file);
}

```

And the `postUrl` is as follows

```auto
postUrl: 'https://novanta.us.cumulocity.com/service/templates-basic/api/ErrorLogsAnalysis'

```

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [January 29, 2024, 7:54pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/9 "2024-01-29T19:54:22Z")

</div>

So the postUrl part, you want to change to just: `/service/templates-basic/api/ErrorLogsAnalysis`.  
As this might otherwise cause issues during local development.

From where did you import `FormData`?  
Can you give it a try with just an empty string as body? To see if it then performs at least the request?

---

<div class="post-metadata">

**Author:** ![luclib](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@luclib](https://community.cumulocity.com/u/luclib)\
**Post date:** [January 29, 2024, 9:51pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/10 "2024-01-29T21:51:27Z")

</div>

Hi Tristan,

I changed the postUrl to just `service/templates-basic/api/ErrorLogsAnalysis` and it returned the same 401 error as before

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/6/4/6497dcc07e5fd5019059a22c9fe1975a75251de7.png)

The `FormData` is not imported from anywhere and is part of the XMLHttpRequest API.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/c/1/c112e8f3358fa0d65073d485c073647443ab2b56.png)

When I send it without appending anything to the new object, I get this error instead

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/6/5/657d855849cbc1d383a9c82f861c9295a210596f.png)

---

<div class="post-metadata">

**Author:** ![Cyril\_Poder](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/cyril_poder/32/17142_2.png) [@Cyril\_Poder](https://community.cumulocity.com/u/Cyril_Poder)\
**Post date:** [January 30, 2024, 2:02am UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/11 "2024-01-30T02:02:37Z")

</div>

Hi,

I don’t get it: why is there an authorization header in your fetch request?  
Please remove that, you don’t need it if this app is supposed to run in Cumulocity.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [August 16, 2024, 4:39pm UTC](https://community.cumulocity.com/t/c8y-application-requiring-a-second-login/7763/13 "2024-08-16T16:39:52Z")

</div>

Closed on August 16, 2024, 4:39pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
