Jwt-auth: auth()->attempt() returns boolean on Laravel 6

Created on 3 Oct 2019  路  2Comments  路  Source: tymondesigns/jwt-auth

Subject of the issue

$token = auth()->attempt($request->only(['email', 'password']));
Returns true on Laravel 6, and not token.

Your environment

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 6.0.0
| Package version | 1.0.0-rc.5
| PHP version | 7.2.4

Steps to reproduce

$token = auth()->attempt($request->only(['email', 'password']));
Previously returned actual token on Laravel 5.8

Expected behavior

$token = auth()->attempt($request->only(['email', 'password']));
Should return token if attempt is successfull.

Actual behavior

$token = auth()->attempt($request->only(['email', 'password']));
Returns true on Laravel 6.

Most helpful comment

For people having the same problem use:
$token = auth('api')->attempt($request->only(['email', 'password']))
instead of:
$token = auth()->attempt($request->only(['email', 'password']));

All 2 comments

For people having the same problem use:
$token = auth('api')->attempt($request->only(['email', 'password']))
instead of:
$token = auth()->attempt($request->only(['email', 'password']));

`
/**

  • Attempt to authenticate a user using the given credentials.
    *
  • @param array $credentials
  • @param bool $remember
  • @return bool
    */
    public function attempt(array $credentials = [], $remember = false);
    `
    How does changing the guard make it return something different to the bool field?
Was this page helpful?
0 / 5 - 0 ratings