lundi 14 mars 2016

profile is not showing when I login with facebook using satellizer with laravel

I know my question is not specific but I want to discuss my problem.

I want to do social login in angular with laravel so I am using satelizer social login. Login and logout is working fine but When I click on profile it's showing en error. I don't know where is the problem. Please help me out If anyone have a solution. Error is enter image description here

and my code is :-

angular Routes

 $stateProvider.state('profile', {
        url: '/profile',
        templateUrl: 'partials/profile.html',
        controller: 'ProfileCtrl',
        resolve: {
          loginRequired: loginRequired
        }
      });

Profile Controller

angular.module('MyApp')
  .controller('ProfileCtrl', function($scope, $auth, toastr, Account) {

    $scope.getProfile = function() {
      Account.getProfile()
        .then(function(response) {
          $scope.user = response.data;
        })
        .catch(function(response) {
          toastr.error(response.data.message, response.status);
        });
    };
    $scope.getProfile();

Account Service

angular.module('MyApp')
  .factory('Account', function($http) {
    return {
      getProfile: function() {
        return $http.get('/satellizer/examples/server/php/public/api/me');
      },
      updateProfile: function(profileData) {
        return $http.put('/satellizer/examples/server/php/public/api/me', profileData);
      }
    };
  });

Laravel Routes // API Routes.

Route::get('api/me', ['middleware' => 'auth', 'uses' => 'UserController@getUser']);

Laravel COntroller

<?php 
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Config;
use Firebase\JWT\JWT;
use App\User;

class UserController extends Controller {

    /**
     * Generate JSON Web Token.
     */
    protected function createToken($user)
    {

        $payload = [
            'sub' => $user->id,
            'iat' => time(),
            'exp' => time() + (2 * 7 * 24 * 60 * 60)
        ];
        return JWT::encode($payload, Config::get('app.token_secret'));
    }

    /**
     * Get signed in user's profile.
     */
    public function getUser(Request $request)
    {

        $user = User::find($request['user']['sub']);
        return $user;
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire