Support the ongoing development of Laravel.io →
Authentication

Is there anyone familiar with s built with running on one domain (laravelapi.com) and apps connecting to it from another domain (angularapp.com)?

How did you handle the authentication session?

Imagine there is a route in the API like /auth/get-user, which does this:

AuthController extends Controller
{
    //Accessed through /auth/get-user
    public function getUser()
    {
        return Response::json(Auth::user());
    }
}

As long as the app and the API are in the same domain, the above code works fine, but when I move them to separate domains, the API just returns a 401 Unauthorized error.

I have set the above error to be returned when ! Auth::check ().

So simply, Laravel's auth session doesn't persist when requested through another domain. How would you face this issue?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

budhajeewa budhajeewa Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.