Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

demo2 with Angular(Frontend) + .net-core(Backend) - Login Error - net::ERR_CERT_AUTHORITY_INVALID


When I send a POST request, for my login API in .net-core 6.0 I have this error in the console:

auth.service.ts:56 
err HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "

zone.js:2680
POST net::ERR_CERT_AUTHORITY_INVALID


- The template returns: wrong user or password.
- I can access the API with Insomnia, for example, without errors.
- The certificate was installed on Browser correctly


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


Hi,

We are not big experts in backend integration (especially with ASP.NET Core) and can't help you with this. Anyway, just try to debug your requests in the development tools and change Auth/User models if your API asks for different models.

Regards,
Keenthemes support



I fix the CORS error.
Now the request arrives at the API correctly, but the login method don't create a token.


login(username: string, password: string): Observable<UserType> {
this.isLoadingSubject.next(true);
return this.authHttpService.login(username, password).pipe(
map((auth: AuthModel) => {
const result = this.setAuthFromLocalStorage(auth);
return result;
}),
switchMap(() => this.getUserByToken()),
catchError((err) => {
console.error('err', err);
return of(undefined);
}),
finalize(() => this.isLoadingSubject.next(false))
);
}


The method dont call setAuthFromLocalStorage function, I don't know why .. and I have a HttpErroResponse error on console (400 Bad Request)



Hi,

Could you please your localStorage, can you see the authToken here?
Also please check the response from ${API_USERS_URL}/login request. Does it return all AuthModel fields? (src/app/modules/auth/models/auth.model.ts)

Regards,
Keenthemes support



HI,

Thanks for your help.

The response from ${API_USERS_URL}/login returns an error in console:

HttpErrorResponse {
headers: HttpHeaders, status: 200, statusText: 'OK', url: ' ok: false, ..}
error: { error: SyntaxError: Unexpecdted token e in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad ( at _ZoneDelegate.invokeTask ...
stack:
"SyntaxError: Unexpected token e in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.onLoad (
at _ZoneDelegate.invokeTask (
at Object.onInvokeTask (
at _ZoneDelegate.invokeTask (
at Zone.runTask (
at ZoneTask.invokeTask [as invoke] (
at invokeTask (
at globalCallback (
at XMLHttpRequest.globalZoneAwareCallback (
text (this is my token, the api returns correctly for the application): "eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTUxMiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoibGVvIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xl"}


So, the API returns correctly token for the application, but we have a JSON parse error.



It's trying to read from localStorage your accessToken.
Try to debug getAuthFromLocalStorage method. It will help you understand the issue then.

Regards,
Keenthemes support


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(