Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created March 10, 2018 00:35
Show Gist options
  • Select an option

  • Save brunokunace/292974ffe2a360a5ac72b459a4647fe6 to your computer and use it in GitHub Desktop.

Select an option

Save brunokunace/292974ffe2a360a5ac72b459a4647fe6 to your computer and use it in GitHub Desktop.
public function authenticate()
{
$credentials = request()->only('cpf', 'password');
try
{
$token = JWTAuth::attempt($credentials);
if(!$token){
$credentials['email'] = $credentials['cpf'];
unset($credentials['cpf']);
try
{
$token = JWTAuth::attempt($credentials);
if(!$token){
return response()->json(['error' => 'Dados Incorretos'], 401);
}
}catch (JWTException $e)
{
return response()->json(['error' => 'something_wrong'],500);
}
}
}catch (JWTException $e)
{
return response()->json(['error' => 'something_wrong'],500);
}
return response()->json(['token' => $token], 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment