Laravel Manual Auth Doesn't Stay Logged
up vote
0
down vote
favorite
I have an issue with authentication in Laravel 5.7
For example purposes, I have setup a fresh Laravel 5.7
install with Users
seed in the database
in the web.php
file :
Route::get('/', function () {
if (!auth()->check()) {
dump('Not Logged');
auth()->login(AppUser::first(), true);
dump(auth()->user()->toArray());
} else {
dump('Logged');
}
What I expect is to have a Not logged
the first time I visit the page, then a Logged each time I refresh the page.
But every time I have a Not logged
response.
Does anyone know how to keep a user logged in manually?
laravel authentication eloquent laravel-5.7
add a comment |
up vote
0
down vote
favorite
I have an issue with authentication in Laravel 5.7
For example purposes, I have setup a fresh Laravel 5.7
install with Users
seed in the database
in the web.php
file :
Route::get('/', function () {
if (!auth()->check()) {
dump('Not Logged');
auth()->login(AppUser::first(), true);
dump(auth()->user()->toArray());
} else {
dump('Logged');
}
What I expect is to have a Not logged
the first time I visit the page, then a Logged each time I refresh the page.
But every time I have a Not logged
response.
Does anyone know how to keep a user logged in manually?
laravel authentication eloquent laravel-5.7
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an issue with authentication in Laravel 5.7
For example purposes, I have setup a fresh Laravel 5.7
install with Users
seed in the database
in the web.php
file :
Route::get('/', function () {
if (!auth()->check()) {
dump('Not Logged');
auth()->login(AppUser::first(), true);
dump(auth()->user()->toArray());
} else {
dump('Logged');
}
What I expect is to have a Not logged
the first time I visit the page, then a Logged each time I refresh the page.
But every time I have a Not logged
response.
Does anyone know how to keep a user logged in manually?
laravel authentication eloquent laravel-5.7
I have an issue with authentication in Laravel 5.7
For example purposes, I have setup a fresh Laravel 5.7
install with Users
seed in the database
in the web.php
file :
Route::get('/', function () {
if (!auth()->check()) {
dump('Not Logged');
auth()->login(AppUser::first(), true);
dump(auth()->user()->toArray());
} else {
dump('Logged');
}
What I expect is to have a Not logged
the first time I visit the page, then a Logged each time I refresh the page.
But every time I have a Not logged
response.
Does anyone know how to keep a user logged in manually?
laravel authentication eloquent laravel-5.7
laravel authentication eloquent laravel-5.7
edited Nov 12 at 11:44
Universal Link
12912
12912
asked Nov 12 at 10:06
Mathieu Ferre
1,264322
1,264322
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I wouldn't advise building an authentication on the web.php route file, you should try to split up the code in an organized way.
Beware of !auth()->check()
, because you're not exactly evaluating if it's false, you are validating the inversion of a bool. Meaning, if it's true, it's going to check if it's false.
Do you have a record in your User table?
Where are you storing your session, in a file or database?
Attempt Auth::login(AppUser::first(), true);
and print out if the user is indeed logged with dd(Auth::user())
https://laravel.com/docs/5.7/authentication#authenticating-users
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump theauth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one
– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
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/3.0/"u003ecc by-sa 3.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%2f53259872%2flaravel-manual-auth-doesnt-stay-logged%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I wouldn't advise building an authentication on the web.php route file, you should try to split up the code in an organized way.
Beware of !auth()->check()
, because you're not exactly evaluating if it's false, you are validating the inversion of a bool. Meaning, if it's true, it's going to check if it's false.
Do you have a record in your User table?
Where are you storing your session, in a file or database?
Attempt Auth::login(AppUser::first(), true);
and print out if the user is indeed logged with dd(Auth::user())
https://laravel.com/docs/5.7/authentication#authenticating-users
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump theauth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one
– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
add a comment |
up vote
0
down vote
I wouldn't advise building an authentication on the web.php route file, you should try to split up the code in an organized way.
Beware of !auth()->check()
, because you're not exactly evaluating if it's false, you are validating the inversion of a bool. Meaning, if it's true, it's going to check if it's false.
Do you have a record in your User table?
Where are you storing your session, in a file or database?
Attempt Auth::login(AppUser::first(), true);
and print out if the user is indeed logged with dd(Auth::user())
https://laravel.com/docs/5.7/authentication#authenticating-users
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump theauth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one
– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
add a comment |
up vote
0
down vote
up vote
0
down vote
I wouldn't advise building an authentication on the web.php route file, you should try to split up the code in an organized way.
Beware of !auth()->check()
, because you're not exactly evaluating if it's false, you are validating the inversion of a bool. Meaning, if it's true, it's going to check if it's false.
Do you have a record in your User table?
Where are you storing your session, in a file or database?
Attempt Auth::login(AppUser::first(), true);
and print out if the user is indeed logged with dd(Auth::user())
https://laravel.com/docs/5.7/authentication#authenticating-users
I wouldn't advise building an authentication on the web.php route file, you should try to split up the code in an organized way.
Beware of !auth()->check()
, because you're not exactly evaluating if it's false, you are validating the inversion of a bool. Meaning, if it's true, it's going to check if it's false.
Do you have a record in your User table?
Where are you storing your session, in a file or database?
Attempt Auth::login(AppUser::first(), true);
and print out if the user is indeed logged with dd(Auth::user())
https://laravel.com/docs/5.7/authentication#authenticating-users
answered Nov 12 at 10:16
abr
1,206928
1,206928
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump theauth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one
– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
add a comment |
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump theauth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one
– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump the
auth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one– Mathieu Ferre
Nov 12 at 10:22
Yeah I know it's just an exemple build from a fresh laravel installation, that's why I just put it on the web file :) I have some record in the User table (if I dump the
auth()->user()
right after the login, it works fine) I am logged for the rest of the request, but don't stay logged for the next one– Mathieu Ferre
Nov 12 at 10:22
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
print the Auth::user() to confirm that your user is indeed logged
– abr
Nov 12 at 10:24
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Just edit the question with the results
– Mathieu Ferre
Nov 12 at 10:27
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
Auth component is working as expect, you can check if it's logged by creating a different route (Route::get(/test)) and print there the auth->user(). Also, just simplify the if statement, if (auth->check()) its logged, otherwise dump
– abr
Nov 12 at 11:00
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53259872%2flaravel-manual-auth-doesnt-stay-logged%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