POST http://127.0.0.1:8000/api/login 401未授权

问题描述

我找不到这个错误的解释,我什至不知道我应该在这里发布什么代码,所以我真的需要指导和帮助,谢谢。

这是CORS.PHP

public function handle($request,Closure $next)
{
    //autorisation a la partie front pour utiliser les methode dans la partie back ...
    //header('Acess-Control-Allow-Origin: Content-type,X-Auth-Token,Authorization,Origin');
    return $next($request)
    ->header('Access-Control-Allow-Origin','*');
    header("Access-Control-Allow-Methods","*");
}

AuthController 中的登录功能

public function login()
{
    $credentials = request(['email','password']);

    if (! $token = auth()->attempt($credentials)) {
        return response()->json(['error' => 'Unauthorized'],401);
    }

    return $this->respondWithToken($token);
}

这是在jawis.service.ts 中的登录

  login(data) {
    return this.http.post('http://localhost:8000/api/login',data,httpOptions)
  }

这是 authentication.service.ts :

   login(data) {
        console.log(data);
        return this.http.post<any>(`${environment.apiUrl}/api/login`,data)
            .pipe(map(user => {
                // store user details and jwt token in local storage to keep user logged in between page refreshes
                localStorage.setItem('currentUser',JSON.stringify(user));
                this.currentUserSubject.next(user);
                console.log('currentUser',user); 
                localStorage.setItem('isloggedin','true');
                // user = JSON.parse(localStorage.getItem('currentUsers'));
                return user;
            }));
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)