#How do I separate logins between two different frontends sharing one Laravel API?

5 messages · Page 1 of 1 (latest)

fickle wigeon
#

Hello, I have two different frontend applications sharing one Laravel API. I use cookie-based authentication. How can I log in to one application without logging in to the other at the same time?

fickle wigeon
#

I tried to add a function to AppServiceProvider that dynamically sets the cookie name differently for each frontend based on the origin header (they are on different subdomains). Thanks to this, when I log in on one frontend, I am not logged in on the other.

However, there is another problem: I load frontend 1, then I load frontend 2, and when I want to submit a form from frontend 1, I get a CSRF error. What can I do about this, please?

spark timber
#

have you considered using jwt or adding a column on the session row like a "app_id" or something?

fickle wigeon
#

I don't really want to switch to token-based authentication because I already use cookie-based authentication in the application (as recommended in the documentation for spa).

What do you mean by app_id row?

fickle wigeon
#

I would prefer to have separate sessions for each subdomain without causing CSRF problems. Is there a solution for this?