Login was previously working but seems to have been been broken.
| Bug? | yes
| Framework | Laravel
| Framework version | 5.5.*
| Package version | dev-develop 60103d1
| PHP version | 7.2
Set up jwt auth set up as explained here.
Token should be generated.
{
"message": "Type error: Argument 2 passed to Lcobucci\\JWT\\Signer\\Hmac::createHash() must be an instance of Lcobucci\\JWT\\Signer\\Key, null given, called in .../app/vendor/lcobucci/jwt/src/Signer/BaseSigner.php on line 34",
"status_code": 500
}
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Requests\LoginRequest;
use App\Exceptions\InvalidCredentials;
use Tymon\JWTAuth\JWTAuth;
use Illuminate\Support\Facades\Auth;
/**
* Class LoginController
* @property JWTAuth JWTAuth
* @package App\Http\Controllers\Auth
*/
class LoginController extends Controller
{
/**
* LoginController constructor.
* @param JWTAuth $JWTAuth
*/
public function __construct(JWTAuth $JWTAuth)
{
/** @var JWTAuth $JWTAuth */
$this->JWTAuth = $JWTAuth;
}
/**
* Log the user in
*
* @param LoginRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function login(LoginRequest $request)
{
$credentials = $request->only(['email', 'password']);
if (!Auth::attempt($credentials)) {
throw new InvalidCredentials('Invalid email or password provided.');
}
$token = $this->JWTAuth->fromUser(Auth::user());
return response()
->json([
'status' => 'ok',
'token' => $token,
'expires_in' => $this->JWTAuth->factory()->getTTL() * 60
]);
}
}
NB:
Dumping Auth::user() returns a perfectly fine User instance.
Try running php artisan jwt:secret
Worked like a charm. Thanks @redolivedev I recently switched computers so I didn't have the key.
I am still having the same problem on laravel v5.6.* . running artisan jwt:secret did not help, I have followed the same instructions as in the page specified above
Same here @i1990jain any joy sorting?
Just sorted - run
php artisan cache:clear
php artisan config:clear
@redolivedev 's answer worked!
鎴戜篃閬囧埌杩欐牱鐨勯棶棰橈紝閲嶆柊鐢熸垚绉橀挜涔熸病鏈夌敤
Same here @i1990jain any joy sorting?
Just sorted - run
php artisan cache:clear
php artisan config:clear
Work perfectly!! :D Thanks so much!
Most helpful comment
Try running
php artisan jwt:secret