I am facing token mismatch issue in new server while working fine in localhost. I have tried every possible way to clear cache and give SESSION_DOMAIN path in env but all seems useless.
Also session cookies are not being created in web browser while creating in storage/framework/session folder.
Please help me !
Are you getting tokenMismatchException exception?
If yes, some of the possible reasons are:
Check your files for PHP end tag "?>", if exists remove it. For more detail refer to this link.
You may need to use web middleware. For more detail refer to this link (although it is about laravel 5.2 but, it may work for your situation too).
Another thing to try is checking for web middleware presence. Normally it should be automatically applied to routes/web.php
Route::group(['middleware' => ['web']], function () {
<routes>
});
Also check out https://laravel.com/docs/5.3/upgrade to see if you have any code that might have been influenced by this update.
And lastly, it would be nice if you could post a piece of code which is responsible for sessions in your app.
Related
I made webpage with Laravel which next I put on private server. After doing that I found out that my links to named routes aren't working.
After online research and talking with server administrator I learned that route() helper in Laravel is using request domain to build links, and that this server will always give me IP address instead of domain and that it is impossible on this server to access anything via IP address, it needs to be via domain.
Because of need to quick dealing with the problem I temporary made custom helper that using route() inside of it and changing IP address in result to app domain (taken from config). It works fine but I can't use third party libraries thanks to that. And I don't like it.
I tought about using middleware on whole app to change that IP address in request on domain but I have no idea (And I couldnt find it in Google) how to do that so route() helper would read it properly. Can you give me any ideas about that?
Thanks in advance.
You can do this little hack if your APP_URL env variable is not working for whatever reason. In your AppServiceProvider boot function add the following:
$this->app->resolving(UrlGenerator::class, function (UrlGenerator $generator) {
$generator->forceRootUrl(env('APP_URL'));
});
This should force a new root url when resolving the url generator.
Seems like there are a lot of posts related to authentication and redirects, but I can't seem to find exactly what I need. I feel like it should be simple.
So, we have a system whereby we want users to enable 2FA and change their passwords every 60 days. We are using Laravel 8 with Jetstream. I am doing a check on login (via modifying config/fortify.php), which works fine, if the password needs to be changed or if they don't have 2FA they get directed on login to their profile page and they see a message saying they need to update their details.
The problem is they can then navigate to any other page without updating anything. Ideally I want them to be redirected back to the profile page until they update their info.
We have the routes inside a middleware group:
Route::middleware(['auth:sanctum', 'verified'])->group(function() {
routes here
});
I thought I could just add a check before any routes load using Auth::user(), but the array is empty and therefore any vars accessed are null.
Auth::users()->role;
I was hoping for something like:
Route::middleware(['auth:sanctum', 'verified'])->group(function() {
if (pass needs resetting and current route isn't profile) {
redirect('/profile');
}
});
I'm assuming that Laravel doesn't authenticate the user until after the middleware has run? Not sure, but that would explain the null values.
So, how would you guys accomplish this? Do I need to modify a controller instead? I just need the user to stay on their profile page until they have updated their data, then they can proceed as normal.
Many thanks for your help.
My Laravel 5.6 project was working well.
But suddenly when I try to login sometimes it says
The page has expired due to inactivity.
and sometimes it login properly with out any error. For example
I go to page 127.0.0.1:8000/login...submit login form and get that error.
I refresh the 127.0.0.1:8000/login page...submit...again error.
I refresh the 127.0.0.1:8000/login page...submit and it works properly :|
Anybody know whats wrong with my project?!
this project works on my host without any problem and I have {{ csrf_field }} in my form.
I've tried to clear cache, view, route, config and deleting browser cache/cookie
and change SESSION_DRIVER=array but still got error.
UPDATE :
another thing that i should say is when it work properly and i login to the panel...when i submit any forms i got out of the panel and i should login again.
for localhost development open kernel.php inside Http folder and just comment this line :
\App\Http\Middleware\VerifyCsrfToken::class,
the csrf protection of laravel doesn't work properly on localhost. I already tried everything. just comment that, it's very annoying problem.
finaly...after 3 bad days focus on this issue...i find the answer and i hope it help someone else :
check your browser setting -> cookies and see how many cookies create
when a user login.
by default laravel create 2 cookies when user login with names :
"XSRF-TOKEN"
"laravel_session"
these are ok but other cookies which you create manually or other installed packages creates cause this problem.
i was using eloquent-viewable package and it creates a cookie everytime i logged in.
i remove this package and then everything works properly :)
Fairly new to Laravel here and I'm struggling to understand how to make Laravel 5.2 aware of where it resides. Here's the issue:
I set up auth using php artisan make:auth, and can now see the lovely landing page, as well as login and register links in the menu. The problem is that these links don't go to the right place. They point to /login and /register in the code respectively, which translates into http://localhost/login or http://localhost/register. But since I'm not on a production site yet and am developing locally, my website resides at http://localhost/projectname/public.
I've gone into config/app.php and tried various values for the URL parameter, but these have no effect.
What can I do to get these links to reflect the full site URL, without manually entering it each time?
you can run the development server in laravel using this command
php artisan serve
Did you try that?
Use laravel url function:
{{ url().'/login' }}
I am using laravel 5.1 and I am trying to make it possible for users to log in to my app. I'm doing this in xampp, so my login path looks like this: http://localhost/laravel/public/index.php/auth/login.
However, when I try to log in it redirects me to http://localhost/auth/login and gives a 404 error. It does this too when the login fails. I have tried to set the 'protected $redirectPath' and 'protected $loginPath' in the AuthController to something like localhost/laravel/public/index.php/ to get to the home page, but it doesn't work and still goes to http://localhost/auth/login. I would be very grateful to anyone that could help me out or explain to me how I can make the redirecting work after logging in or failing to log in.
Just fixed my own problem: it turns out that I was posting my login form to /auth/login (I had just copied the example from the laravel docs), so I changed that to /laravel/public/index.php/auth/login and now everything is acting as it should again!
its better to use
php artisan serve
in your project route if you're developing in localhost because you can control your routes more easily and you can get rid of localhost/laravel/public/index.php/ .