dimanche 25 octobre 2015

Get Auth::user returning null

I'm trying to access my Authenticated user from an external application, but using Auth::user() returns null even after I've successfully logged the user in.

Frontend:

    //First, let user register
    API.Auth.register(params).done(function (result) {
        ...
        //Then automatically create a new game using their Auth'ed $user in backend
        API.User.newGame().done(function (result) {

Laravel:

public function postRegister(Request $request)
{
    ...

    //Login the new user
    Auth::login($this->create($request->all()));

    //Successfully returns auth'ed user
    return new Response(Auth::user(), 200);
}

public function newGame()
{

    Auth::loginUsingId(1); //This works

    $user = Auth::user(); //Returns null

    $totalUserGames = UserStats::where('user_id', '=', $user->id)->count();
    ...

Error: Trying to get property of non-object



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire