Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MarkusHH78's avatar

Laravel 9 Single Sign On

Hi guys, maybe i think overclomplicatded but i need the following:

  • I have two (or more) applications AND only ONE User-DB.
  • Auth and roles and permissions are stored in this User-DB
  • After login in this User-Managament-App i want the users auto logged in in other pages where they have access

I don't know if i need oAuth or Socialite for this?! Maybe there is an easyer way for this?

I'm very thankful for any tipps.

0 likes
8 replies
chiefguru's avatar

@markushh78 you could simply create a DB connection for your user DB and another connection for everything else and set the User model connection to use the user DB connection.

Use the same user DB connection for each of your sites. You'd have to check that your roles and permission models also use the same connection of course.

1 like
MarkusHH78's avatar

@chiefguru Yes this is my current system construct. I already have one user DB. Both sites login can login over this user db. But when i am logged in in site A i am not logged in automatically in site B!.

1 like
chiefguru's avatar

@markushh78 how are you switching between sites?

if it's a login to A and click a button to get to B and vice-versa then you could exchange a token that then logs you in on the other site pushing login stuff into the session.

1 like
MarkusHH78's avatar

@chiefguru Yes, thats the way... Login on site A, click a link to get to site B. Your suggestion is good that's how I do it now:

  • Login site A
  • Click a link to site B with encrypted/tokenized user email and encrypted and hashed password
  • On site B get user by decrypted email and check password hash
  • Then Auth::loginUsingId(ID)
1 like
MohamedTammam's avatar

If they're in the same domain, add the base domain to the session for both apps and share the same app keys in the .env between both apps.

1 like

Please or to participate in this conversation.