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

devondahon's avatar

Multiple domain names API with Sanctum

Knowing that to use Sanctum, SPA and API must share the same top-level domain, if I set multiple domain names for my api, like api.foo.com, api.bar.com, can I then use Sanctum with different frontends like www.foo.com and www.bar.com, each frontend using its own api guard (and user database) ?

The api and the frontends foo and bar are on three different servers.

In order to authenticate, your SPA and API must share the same top-level domain. However, they may be placed on different subdomains.

0 likes
3 replies
martinbean's avatar

@devondahon Well your question is answered in the text you’ve quoted. No, they must have the same top-level domain.

devondahon's avatar

@martinbean If api.foo.com and api.bar.com point to the same IP address of my Laravel App, then the two frontends www.foo.com and www.bar.com are respectively on the same top-level domain as api.foo.com and api.bar.com. Is there something wrong in this reasoning that would make Sanctum unsuitable in such configuration ?

martinbean's avatar

They’re not though: foo.com and bar.com are two, different top-level domains. It doesn’t matter if they’re on the same server; they’re still two different domain names.

Please or to participate in this conversation.