Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Laravel user is logged out after redirecting back from payment?

Tags:

laravel

I deployed my Laravel app to shared hosting (cpanel). For paying, the user first redirects to a bank account and then redirects to my page. during this procedure, the user gets logged out!

for protecting my routes I use auth middleware and for session driver, I use the default session driver which is file. also, the permission for framework/sessions is 777.

this is the code which redirect to the bank page:

            $go = "https://thebank/example";
            redirect()->to($go)->send();

and after a successful payment, the bank redirects to a route that I specified for verifying the payment.

Route::get('/payment/callBack' , 'PaymentController@VerifyData')->middleware('auth');

the route utilizes the auth middleware However most of the time the user is not logged in and automatically redirects to login page. I noticed if I don't use the auth middleware and if the user refreshes the page the user logs in automatically. this is not something that usually happens with laravel. I also tried the cookie driver for session and it didn't work and caused more problems.

I also didn't gain any success in storing user_id and cart_id in the default PHP $_SESSION. all SESSIONS seems to be cleared when user redirects back from the bank page.

how can I fix the problem?

like image 647
Hadi Aghandeh Avatar asked Jan 22 '19 05:01

Hadi Aghandeh


1 Answers

The same_site setting is changed in default Laravel installation, make sure you change same_site to null in config/session.php or callback won't include cookies and you will be logged out when a payment is completed. So inside your config/session.php update

return [
  ...
  ...
  'same_site' => null,
  ...
  ...
];
like image 190
CodingEra Avatar answered Nov 15 '22 07:11

CodingEra