Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created February 16, 2018 01:16
Show Gist options
  • Select an option

  • Save brunokunace/8aa4644500b5f8569984e890977a4797 to your computer and use it in GitHub Desktop.

Select an option

Save brunokunace/8aa4644500b5f8569984e890977a4797 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