There is a problem with my Laravel App, whenever a user logs in it logs the user in.
At this point if i return a view it still stays logged in but if i redirect to any route at all (protected or not), it automatically logs the user out and redirects to login page.
You session and auth guard is not configured properly please check this and also you can use laravel auth package for login/register
So i resolved it following this :
SOLUTION:
Go to your .env file and change SESSION_DRIVER=file to SESSION_DRIVER=database.
Next you will need to create a session migration: php artisan session:table.
Now composer dump-autoload for good practice.
Finally migrate (php artisan migrate).
Related
When trying to access a protected route or just refreshing the page the session is lost, so I have to login again. What I don't understand is that sometimes this problem does not happen but most of the time it does and sometimes it takes more than 3 times of doing the login before I can finally access a protected route. This only happens in production. I have no idea but it started only after I moved my hosting to Cloudways and users start complaining.I have other Laravel app with version 5.4 on the same server without problems.
1- change your session driver value to database then the user's session will be stored inside your database, sessions table instead of file:
in your .env file set :
SESSION_DRIVER=Database
2- clean cache and config
php artisan config:clear
php artisan cache:clear
I've made a new installation of Voyager on XAMPP on Windows following the instructions at https://github.com/the-control-group/voyager
I forgot to install with dummy data so I added an admin user using php artisan voyager:admin me#mydomain.com --create however when I try to login I get the 419 | Page Expired error which I understand is usually an issue with Laravel sessions.
My versions are: Voyager v1.4 | Laravel v7.18 | PHP v7.3.2 | MySql v5.0.12
The following points maybe relevant:
If I look at the login page source code I don't see any reference to a csrf field.
Looking in the database the user exists in the user table, and I entered an email_verified_at date directly.
I notice there's no entry in the user_roles table. I don't know what minimum database entries are required to make it work.
I've checked that session files are being created in storage/framework/sessions/
There's no error log in storage/logs/
I set 'debug' => env('APP_DEBUG', true), in config/app.php (APP_DEBUG was already set to true in .env) and retried the login but not found any debug log file.
I'm new to Voyager and still learning Laravel. Any ideas please how to make it work please?
UPDATE:
After several refreshes of the login page I was able to login, but if I click any menu link it returns me to the login page.
UPDATE2:
Re-running the install with dummy data succeeded but it didn't alter the login session issue. However it works perfectly on another device, so it must be some kind of browser session issue particular to the one PC.
Incidentally running the install with dummy data did not add any entries in the user_roles table, but the admin role is assigned when viewed in the users screen (on my other device).
I was getting this same error, i was serving my app on 127.0.0.1:8000 and my SESSION_DOMAIN was set on localhost. Make Sure you SESSION_DOMAIN in your env is set to the actual domain the app is being served on. Theissue was fixed by running php artisan serve --port=80 and browing to localhost/admin to login
My project crashes on login screen. It tries to get password.request route which it does not see. In routing, there is of course
Auth::routes();
but I did add some other stuff that uses authentication mechanisms. I copied remember password views and controllers from vendors and renamed them to reuse for other purposes.
To be honest I don't even know how to debug missing route. Any help?
You shouldn't have to copy views and controllers from the vendors folder manually if you're doing things with Laravel. Instead run php artisan make:auth in a console. This command will copy the necessary auth blade templates and update your routes/web.php to suit. There is some more info here in the official docs on Laravel authentication.
Also, if you haven't already, you'll need to run migrations by running php artisan migrate in a console. This will create the users and password_resets tables needed to allow registration, login and password recovery.
If you're still having trouble and want to debug things more, make sure you set APP_DEBUG=true inside your .env file in the projects root path. This should record a stack trace in storage/logs/laravel.log when an error occurs.
There are a couple of questions like this, but none of them worked for me.
I have a new project in Laravel. I created new /register route, works perfectly.
But /login is not working. I'm getting 403 Forbidden error and nginx/1.13.3 beneath. I tried adding new .htaccess file in the root of the project and it didn't work.
I have a project that I created couple of months ago, with the same route /login and it still works perfectly, with no .htaccess fine in root.
I'm using Homestead machine as the server and I have Laravel 5.6.1. project.
And, no matter what I do, the same error is still there. I can remove the route, the controller or the view (just to provoke new, familiar error) but still the same one.
Any ideas what is going on?
First, nginx doesn't need an .htaccess file. It exists for apache users in new Laravel projects.
Second, Laravel has the authentication routes builtin, you shouldn't need to create login and register routes. Run:
php artisan make:auth
to scaffold your auth routes and views. Try removing the /register route you created and run the above command.
Just run
php artisan make:auth
and
php artisan migrate
in a fresh Laravel application.
Then, navigate your browser to
http://your-app.dev/register
or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system!
I have a issue in my laravel applications, i'm using XAMPP test run my applications locally on windows machine.
My problem is that Laravel applications get's logout suddendly, this happens very often, if i refresh the same page like 4 , 5 times it get's logged off. but when i check the chrome dev tools Cookies, Laravel_session is still there.
Any idea as to why this could happen?, also, i don't get the same issue when it's hosted online.
May be the problem is with session driver. Because as you said that if i refresh the same page like 4 , 5 times it get's logged off, by default session storage is file and you 4-5 time request may messing it up. Here I'm not sure but this stuff may solve your issue.
Change SESSION_DRIVER=file to SESSION_DRIVER=database in .env
Create session migration with php artisan session:table artisan
code
Run composer dump-autoload to regenerates the list of all
classes
Run php artisan migrate to migrate.
NOTE: You can run single migration file by separate with subfolder