Laravel login - Fail condition isn't workingWhy does AuthorizeAttribute redirect to the login page for authentication and authorization failures?Reference - What does this error mean in PHP?Laravel - Manual user loginLogin Auth in laravel customsize (SOLUTION)Laravel Login & Registration with Error CodeCan I log a user in with post request rather than through Laravel login page by defaultHow do I log in a user in Laravel?How do I manually authenticate user in Laravel 5.4Laravel 5.5 basic auth login exceptionLaravel redirect failed login: Method loginUsername does not exist
Did Joe Biden "stop a prosecution" into his son in Ukraine? And did he brag about stopping the prosecution?
How to prove (A v B), (A → C), (B → D) therefore (C v D)
Does the DOJ's declining to investigate the Trump-Zelensky call ruin the basis for impeachment?
Is power set functor determined by its image on objects?
Could Boris Johnson face criminal charges for illegally proroguing Parliament?
Can I voluntarily exit from the US after a 20 year overstay, or could I be detained at the airport?
How to define the line style in advance of plot function
Found a minor bug, affecting 1% of users. What should QA do?
Where does the image of a data connector as a sharp metal spike originate from?
Can 35 mm film which went through a washing machine still be developed?
How come the Russian cognate for the Czech word "čerstvý" (fresh) means entirely the opposite thing (stale)?
How to "Start as close to the end as possible", and why to do so?
How to tension rope between two trees?
Are there any tricks to pushing a grand piano?
Using 4K Skyrim Textures when running 1920 x 1080 display resolution?
Why do many websites hide input when entering a OTP
Is there any problem with students seeing faculty naked in university gym?
How to be productive while waiting for meetings to start
Redirect output on-the-fly - looks not possible in Linux, why?
As an interviewer, how to conduct interviews with candidates you already know will be rejected?
C - Learning Linked Lists, Pointer Manipulation - Store some ints, print and free memory
Anonymous reviewer disclosed his identity. Should I thank him by name?
Generating Roman numerals with dice
The decoration of language in proposal writing
Laravel login - Fail condition isn't working
Why does AuthorizeAttribute redirect to the login page for authentication and authorization failures?Reference - What does this error mean in PHP?Laravel - Manual user loginLogin Auth in laravel customsize (SOLUTION)Laravel Login & Registration with Error CodeCan I log a user in with post request rather than through Laravel login page by defaultHow do I log in a user in Laravel?How do I manually authenticate user in Laravel 5.4Laravel 5.5 basic auth login exceptionLaravel redirect failed login: Method loginUsername does not exist
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I'm creating a login api in Laravel.
I have a login method
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
return Response::json(['message' => 'Failed to authenticate'], 401);
If the login fails it doesn't reach the 401 error. Any reason why?
php laravel authentication laravel-5
add a comment
|
I'm creating a login api in Laravel.
I have a login method
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
return Response::json(['message' => 'Failed to authenticate'], 401);
If the login fails it doesn't reach the 401 error. Any reason why?
php laravel authentication laravel-5
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
Did you import theResponse
facade? After a successful attempt, you use theresponse()
helper instead.
– Joel Hinz
Mar 28 at 21:33
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51
add a comment
|
I'm creating a login api in Laravel.
I have a login method
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
return Response::json(['message' => 'Failed to authenticate'], 401);
If the login fails it doesn't reach the 401 error. Any reason why?
php laravel authentication laravel-5
I'm creating a login api in Laravel.
I have a login method
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
return Response::json(['message' => 'Failed to authenticate'], 401);
If the login fails it doesn't reach the 401 error. Any reason why?
php laravel authentication laravel-5
php laravel authentication laravel-5
edited Mar 28 at 21:19
asked Mar 28 at 21:11
user11161143
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
Did you import theResponse
facade? After a successful attempt, you use theresponse()
helper instead.
– Joel Hinz
Mar 28 at 21:33
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51
add a comment
|
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
Did you import theResponse
facade? After a successful attempt, you use theresponse()
helper instead.
– Joel Hinz
Mar 28 at 21:33
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
Did you import the
Response
facade? After a successful attempt, you use the response()
helper instead.– Joel Hinz
Mar 28 at 21:33
Did you import the
Response
facade? After a successful attempt, you use the response()
helper instead.– Joel Hinz
Mar 28 at 21:33
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51
add a comment
|
2 Answers
2
active
oldest
votes
Try
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
else
return Response::json(['message' => 'Failed to authenticate'], 401);
I would also dd()
your auth()
and make sure things are being pass as intended. Are you passing your CSRF token?
Also do you have your Response
loaded using Use ../../Response; at the top of the controller?
add a comment
|
As @kray said, use dd() or echo"";print_r($credentials) to see if data is passed correctly. If not , then may be you haven't include csrf_field() in your form.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406898%2flaravel-login-fail-condition-isnt-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
else
return Response::json(['message' => 'Failed to authenticate'], 401);
I would also dd()
your auth()
and make sure things are being pass as intended. Are you passing your CSRF token?
Also do you have your Response
loaded using Use ../../Response; at the top of the controller?
add a comment
|
Try
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
else
return Response::json(['message' => 'Failed to authenticate'], 401);
I would also dd()
your auth()
and make sure things are being pass as intended. Are you passing your CSRF token?
Also do you have your Response
loaded using Use ../../Response; at the top of the controller?
add a comment
|
Try
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
else
return Response::json(['message' => 'Failed to authenticate'], 401);
I would also dd()
your auth()
and make sure things are being pass as intended. Are you passing your CSRF token?
Also do you have your Response
loaded using Use ../../Response; at the top of the controller?
Try
public function authenticate(Request $request)
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials))
return response()->json(auth()->user());
else
return Response::json(['message' => 'Failed to authenticate'], 401);
I would also dd()
your auth()
and make sure things are being pass as intended. Are you passing your CSRF token?
Also do you have your Response
loaded using Use ../../Response; at the top of the controller?
edited Mar 29 at 0:21
answered Mar 29 at 0:15
KrayKray
4389 silver badges21 bronze badges
4389 silver badges21 bronze badges
add a comment
|
add a comment
|
As @kray said, use dd() or echo"";print_r($credentials) to see if data is passed correctly. If not , then may be you haven't include csrf_field() in your form.
add a comment
|
As @kray said, use dd() or echo"";print_r($credentials) to see if data is passed correctly. If not , then may be you haven't include csrf_field() in your form.
add a comment
|
As @kray said, use dd() or echo"";print_r($credentials) to see if data is passed correctly. If not , then may be you haven't include csrf_field() in your form.
As @kray said, use dd() or echo"";print_r($credentials) to see if data is passed correctly. If not , then may be you haven't include csrf_field() in your form.
answered Mar 30 at 10:11
iamawesomeiamawesome
1476 bronze badges
1476 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406898%2flaravel-login-fail-condition-isnt-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What version of Laravel are you using?
– Rwd
Mar 28 at 21:19
@RossWilson 5.8
– user11161143
Mar 28 at 21:19
You should show us what are you getting instead of 401 error, and how are you getting it
– Snickfire
Mar 28 at 21:26
Did you import the
Response
facade? After a successful attempt, you use theresponse()
helper instead.– Joel Hinz
Mar 28 at 21:33
use try ... catch for catch error if anything missing/wrong in your code
– Ajay
Mar 30 at 10:51