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

devondahon's avatar

How to authenticate to Laravel API on multiple users tables, one per Nuxt frontend

I'm using Laravel as API with different Nuxt frontends on different domains, and I need users to sign in these different frontends, each frontend having its database and users table behind the Laravel API.

I first tried Laravel Passport with client and secret, but there's no user sign in process and it only works with the default users table.

Then, I wanted to try Laravel Passport with Password Grant Tokens, which allows to set a provider per client (in oauth_clients table) and thus allows multiple users table login, but I've read here that it's unsecure.

Then, I decided to try Laravel Sanctum, but it's said in the documentation that SPA and API must share the same top-level domain while my Nuxt SPAs are on their own domains.

How should I handle users authentication in my configuration ?

0 likes
6 replies
bugsysha's avatar
https://www.youtube.com/watch?v=Kd3hcrxtTHA
https://www.youtube.com/watch?v=592EgykFOz4
https://www.youtube.com/watch?v=cjWEZ5SKvIY
https://www.youtube.com/watch?v=Ibd8stzF1KQ
https://www.youtube.com/watch?v=zazeGmFmUxg
https://www.youtube.com/watch?v=F16Qw4zAo28

Also checkout https://github.com/spatie/laravel-multitenancy

Note that you should avoid that approach. You are only making your life harder.

devondahon's avatar

Thanks for your answer! Which approach should I avoid and which approach would you recommend instead ?

bugsysha's avatar

Avoid multiple databases approach. Use single database.

devondahon's avatar

Even with a single database, I still need to have multiple users tables, so the problem still remains. I could merge the users tables into one, but really these users have nothing in common and I'm a bit afraid of mixing everything up.

devondahon's avatar

A solution that may be acceptable is a common very basic users table for all platforms just for signing in, and sub-users tables containing specific information for each platform. But then, if I use Laravel Passport to authenticate, I'd have to redirect the users to the backend to sign in and redirect them back to the platform they come from, which is not user friendly.

bugsysha's avatar

If things are so different between those frontend apps, then they might require separate backend apps.

Please or to participate in this conversation.