Okay, I don't know what I am doing wrong, but I really tried everything. In agular I just send user data to sign up
signUp(userData: LoginData) {
return this.http.post(`${this.rootPath}api/signup`, userData);
}
On backend
public function login()
{
$credentials = request(['email', 'password']);
if (! $token = auth()->attempt($credentials)) {
return response()->json(['error' => 'Email or password doesn\'t exist'],
401);
}
return $this->respondWithToken($token);
}
public function signup(signUp $request)
{
User::create($request->all());
return $this->login();
}
signUp
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required'
];
}
It adds new user to database, but I ALWAYS get 401 error which says user is not authorized. It is strange and I can't unerstand what am I doing wrong... Field REMEMBER_TOKEN is null, but I think it is not the problem...