Jwt-auth: Laravel 5.4 *Always getting invalid_credentials*

Created on 13 Feb 2017  Â·  3Comments  Â·  Source: tymondesigns/jwt-auth

 public function signup(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required'
        ]);
        $user = new User([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('email'))
        ]);
        $user->save();
        return response()->json([
            'message' => 'Successfully created user!'
        ], 201);
    }

    public function signin(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required'
        ]);
        $credentials = $request->only('email', 'password');
        try {
            if (!$token = JWTAuth::attempt($credentials)) {
                return response()->json([
                    'error' => 'Invalid credentials!'
                ], 401);
            }
        } catch (JWTException $e) {
            return response()->json([
                'error' => 'Could not create token!'
            ], 500);
        }
        return response()->json([
            'token' => $token
        ], 200);
    }

//function signin output : {"error":"Invalid credentials!"}

Most helpful comment

Well... your stored password is a bcrypt of user's email addres. You have a typo in your code on signup, it should be

    ...
    $user = new User([
        'name' => $request->input('name'),
        'email' => $request->input('email'),
        'password' => bcrypt($request->input('password'))
    ]);
    ....

All 3 comments

Well... your stored password is a bcrypt of user's email addres. You have a typo in your code on signup, it should be

    ...
    $user = new User([
        'name' => $request->input('name'),
        'email' => $request->input('email'),
        'password' => bcrypt($request->input('password'))
    ]);
    ....

thanks

merci bcp

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NaelsonBrasil picture NaelsonBrasil  Â·  3Comments

functionpointdaniel picture functionpointdaniel  Â·  3Comments

phamduong picture phamduong  Â·  3Comments

gandra picture gandra  Â·  3Comments

agneshoving picture agneshoving  Â·  3Comments