Morning,
I have a bit of an issue which I cannot seem to resolve by myself. I am using the Core+Angular template.
Firstly, I have created a number of AppServices in a separate module (i.e. not in the standard MyProject*.Application project). These are all working fine when using the Swagger UI and Postman.
Then I ran nswag/refresh.bat and referred to the generated ProxyServices as providers in service-proxymodule.ts
I have then created a couple of Components.
- They are declared in main.module.ts
- The ProxyServices are included as providers in main.module.ts
- Added a path for my components in main-routing.module.ts
- Included a link to my page in navigation
When I open the page in a browser I get 401 (Unauthorized). This is because the server is complaining the user hasn't been logged in.
Using Fiddler I notice that my component does not include any auth header tokens.
Below is some sample code from my component:
import { Component, Injector, ViewEncapsulation, OnInit } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PatientsServiceProxy, CreateOrEditPatientDto, GetPatientForEditOutput} from '@shared/service-proxies/service-proxies';
declare let d3, Datamap: any;
@Component({
templateUrl: './patient-details.component.html',
encapsulation: ViewEncapsulation.None,
animations: [appModuleAnimation()]
})
export class PatientDetailsComponent extends AppComponentBase implements OnInit {
ngOnInit(): void {
}
constructor(
injector: Injector,
private _patientsServiceProxy: PatientsServiceProxy
) {
super(injector);
}
active: boolean = false;
saving: boolean = false;
patientId: string;
patient: CreateOrEditPatientDto = new CreateOrEditPatientDto();
savePatient(): void {
this.saving = true;
this._patientsServiceProxy.createOrEdit(this.patient)
.finally(() => { this.saving = false; })
.subscribe(() => {
this.notify.info(this.l('SavedSuccessfully'));
});
}
}
How do I get my component to include the auth? I thought that proxy services would solve that...
5 Answer(s)
-
0
Hi @thor,
Yes, auth token must be added to header automatically.
- Have you upgdated your solution recently (Maybe the version of Angular) ?
- Are the initial services (pages) working for you ? User list page for example ?
If initial pages are working but not yours, could you send your project via email to <a href="mailto:[email protected]">[email protected]</a> ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Yes, I have updated Angular recently. And yes the initial/standard pages are all working.
I will send through the specific feature branch I have been playing around with to the email address below. Do you want all of it?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
We have found the problem. You need to remove the providers array of main.module.ts which is not necessary. Because of this, your services are not intercepted and auth token not added to request headers.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thank you very much!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
thanks for the feedback ;)
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)