Skip to content

CORS error while trying to register #299

@Elie-Soued

Description

@Elie-Soued

Steps to reproduce the issue:
1- Clone repo
2-Run yarn install
3- run ng serve
4-go to the signup section
5-Fill the section with username, email and password
6- click the submit button

Actual
I am getting the below error:
Access to XMLHttpRequest at 'https://api.realworld.io/api/users' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Expected
I can register.

More notes:
I have added the "Access-Control-Allow-Origin" header in the call but I am still getting the same error.

  register(credentials: {
    username: string;
    email: string;
    password: string;
  }): Observable<{ user: User }> {
    
    return this.http
      .post<{ user: User }>("/users", { user: credentials },{headers : {"Access-Control-Allow-Origin" : "*"}})
      .pipe(tap(({ user }) => this.setAuth(user)));
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions