-1

I have a Laravel backend, which allows me to manage the user. I tested the backend with Postman. I could create a user and log in. Now I want to log in with Angular. However, I get a 500th So that's not much start. I have the feeling that it is a header problem. But I do not know why.

my backend here:

https://github.com/TheSlowlySnail/MT_Backend_Iventorysystem

here my service:

    httpOptions = {
    headers: new HttpHeaders({
      /* 'Content-Type': 'application/json', */
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/x-www-form-urlencoded'
    })
  };
  constructor(private http: HttpClient) { }

  signup(username: string, email: string, password: string, c_password: string) {
    return this.http.post('http://127.0.0.1:8000/api/userRegister', { name: username, email: email, password: password,
    c_password: c_password  },
      this.httpOptions).subscribe(
        respone => { console.log(respone); }
      );


  }

here my crontroller:

  constructor(private authService: AuthService) { }

  ngOnInit() {
  }

  onSignup(form: NgForm) {
    this.authService.signup(form.value.username, form.value.email, form.value.password, form.value.c_password);
  }

Error message:

Failed to load http://127.0.0.1:8000/api/userRegister: Response for preflight has invalid HTTP status code 500.

Backend by this tutorial

https://itsolutionstuff.com/post/php-laravel-56-rest-api-with-passport-tutorialexample.html

I do not know how to continue. I have also looked at similar problems, where I've also tried a lot. Unfortunately without success.

Helge
  • 79
  • 3
  • 17

1 Answers1

-1

this is a CORS issue, you have to enable access in your Laravel application.

Take a look at This question which covers just that.

theriddle2
  • 398
  • 3
  • 9
  • Here my Headers public function handle($request, Closure $next) { return $next($request) ->header('Access-Control-Allow-Origin','*') ->header('Access-Control-Allow-Methods','GET, POST,OPTIONS, PUT, PATCH, DELETE') ->header('X-Requested-With' , 'XMLHttpRequest') ->header('Access-Control-Allow-Headers', 'accept, content-type, x-xsrf-token, x-csrf-token, Authorization, Origin'); // Add any required headers here; } – Helge May 14 '18 at 11:27
  • It was a wrong header. I need application/json. Thanks for your Help. – Helge May 15 '18 at 11:28