Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Log In/Authentication Laravel from Other Laravel

I have two Laravel applications that use the same database and, therefore, have the same users and passwords.

Let's say the applications are called A and B.

If a user logs into A, what can I do so that they're automatically logged into B? So if they log into A, then when they go to B, they will not have to type in their login information again.

Both applications are on the same domain, but B is a subdomain and is not part of the same project as A.

Thank you in advance!

like image 781
Aaron Adrian Avatar asked Nov 08 '22 06:11

Aaron Adrian


1 Answers

When you say Both applications are on the same domain, but B is a subdomain and is not part of the same project as A. can i safely assume that they are two separate installations of Laravel, but they share the same database? I that's the case, you could try this:

  • Switch the session driver to database in your .env file to "database", for reference you should look at the comments in config/session.php, near the 'driver' => env('SESSION_DRIVER', 'file'), option. Be sure to manage the tables accordingly (see https://laravel.com/docs/5.5/session#driver-prerequisites)
  • In your .env file, specify this row: SESSION_DOMAIN=.domain.ext (notice the dot near the equal sign).

Alternatively, if even the databases are separate you could try the same config as above using the cookie driver instead fo the database. let me know if this helped.

edit: more a suggestion than an answer, laravel is capable of handling multiple websites/domains natively (example: Route::domain('sub.domain.ext'). Pratically speaking, you organize the routes this way in routes/web.php. With a wise database management (and queries) you can easily mantain 2 separate websites within 1 Laravel application. This assuming you have control over your webserver, of course. If that's the case, i would suggest a refractoring. It's really worth the effort.

like image 143
Aranarth Avatar answered Nov 15 '22 11:11

Aranarth