0

I am developing a website with Angular 15 and I get the data from two APIs. One is public (The Movie Database) and I had no problem working with it.

I developed the other one and is deployed on my school server. I know my API works well because I tested it on several environments. I only have this problem on the website. I need to hide the url for privacy issues.

@Injectable({
  providedIn: 'root',
})
export class LoginService {

  constructor(private httpClient: HttpClient) {}

  public login(userName: string, password: string): Observable<UserRemote> {
    return this.httpClient
      .get<UserRemote>(
        'http://[...]/api/users/login?username=' + userName + '&password=' + password
      )
      .pipe(
        map((response) => {
          return response;
        }),
        catchError((error) => {
          console.log('Error: ' + error.message);
          return throwError(() => error.message);
        }),
      );
  }
}

All I get when running it is "Unkown error": Error image

The only difference I can tell from this url and one from The Movie Database is that it is http:// instead of https://. While working on an Android app, I had the same issue and I could fix it by adding allowcleartext=true, but I can't find the equivalent for Angular.

I tried using: this.sanitizer.bypassSecurityTrustResourceUrl('http://[...]/api/users/login?username=' + userName + '&password=' + password);. I'm not sure how it works, so it probably doesn't make sense here.

maury844
  • 1,210
  • 15
  • 25
BeaBP
  • 3
  • 1

1 Answers1

0

This looks like something CORS-related because the error doesn't say much (and doesn't look like it's being thrown directly from your API either)

You might want to check your Access-Control-Allow-Origin header / configuration

maury844
  • 1,210
  • 15
  • 25