Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active Model Serializers not compatible with currentUser #76

Open
alereisan opened this issue Oct 29, 2015 · 1 comment
Open

Active Model Serializers not compatible with currentUser #76

alereisan opened this issue Oct 29, 2015 · 1 comment

Comments

@alereisan
Copy link

I am using Active Model Serializers Gem and have created an UserSerializer (users_serializers.rb). Since then I cannot access Auth.currentUser() in AngularJS anymore. Everything else (Login/Reg/Oauth) still works... When I remove the UserSerializer Auth.currentUser() is accessible again...

Is there a fix for this issue, or am I just missing something?

@alereisan
Copy link
Author

My UserSerializer, which causes the Problem with Auth.currentUser() looks like this:

class UserSerializer < ActiveModel::Serializer
  attributes :id, :email, :created_at, :updated_at, :username, :provider, :uid, :name, :photo

  has_many :auctions
end

JSON Output with UserSerializer disabled:

{"id":1,"email":"[email protected]","created_at":"2015-10-28T18:21:56.944Z","updated_at":"2015-10-31T14:06:25.846Z","username":"MuteMinute","provider":"facebook","uid":"1***5","name":"Alessandro Santamaria","photo":"http://graph.facebook.com/1***5/picture"}

JSON Output with UserSerializer enabled (includes the auction model):

{"id":2,"email":"[email protected]","created_at":"2015-10-30T12:31:25.480Z","updated_at":"2015-10-30T12:31:25.488Z","username":"simon","provider":null,"uid":null,"name":null,"photo":null,"auctions":[{"id":6,"product":"Ridge Mini Cruiser Penny Skateboard","condition":"Wurde nur ca. 10 mal gefahren, das PennyBoard ist aus Hartplastik uns sehr stabil.","user":{"id":2,"email":"[email protected]","created_at":"2015-10-30T12:31:25.480Z","updated_at":"2015-10-30T12:31:25.488Z","username":"simon","provider":null,"uid":null,"name":null,"photo":null},"created_at":"2015-10-30T12:33:21.295Z","questions":[{"id":18,"body":"Have you driven that skateboard on rainy days?","auction_id":6,"created_at":"2015-10-30T23:38:59.777Z","updated_at":"2015-10-30T23:40:29.219Z","user_id":1,"answer":"Never!","user":{"id":1,"email":"[email protected]","created_at":"2015-10-28T18:21:56.944Z","updated_at":"2015-10-31T14:06:25.846Z","username":"MuteMinute","provider":"facebook","uid":"1***5","name":"Alessandro Santamaria","photo":"http://graph.facebook.com/1***5/picture"}},{"id":19,"body":"How much would shipping to UK be?","auction_id":6,"created_at":"2015-10-30T23:39:46.928Z","updated_at":"2015-10-30T23:40:37.550Z","user_id":1,"answer":"20 Euro","user":{"id":1,"email":"[email protected]","created_at":"2015-10-28T18:21:56.944Z","updated_at":"2015-10-31T14:06:25.846Z","username":"MuteMinute","provider":"facebook","uid":"1***5","name":"Alessandro Santamaria","photo":"http://graph.facebook.com/1***5/picture"}}],"bids":[{"id":20,"amount":5,"auction_id":6,"created_at":"2015-10-30T12:52:27.462Z","updated_at":"2015-10-30T12:52:27.462Z","user_id":11,"user":{"id":11,"email":"[email protected]","created_at":"2015-10-30T12:51:19.082Z","updated_at":"2015-10-30T12:51:19.086Z","username":"thompSon","provider":null,"uid":null,"name":null,"photo":null}},{"id":47,"amount":6,"auction_id":6,"created_at":"2015-10-30T23:40:46.394Z","updated_at":"2015-10-30T23:40:46.394Z","user_id":1,"user":{"id":1,"email":"[email protected]","created_at":"2015-10-28T18:21:56.944Z","updated_at":"2015-10-31T14:06:25.846Z","username":"MuteMinute","provider":"facebook","uid":"1***5","name":"Alessandro Santamaria","photo":"http://graph.facebook.com/1***5/picture"}},{"id":48,"amount":7,"auction_id":6,"created_at":"2015-10-30T23:40:50.235Z","updated_at":"2015-10-30T23:40:50.235Z","user_id":1,"user":{"id":1,"email":"[email protected]","created_at":"2015-10-28T18:21:56.944Z","updated_at":"2015-10-31T14:06:25.846Z","username":"MuteMinute","provider":"facebook","uid":"1***5","name":"Alessandro Santamaria","photo":"http://graph.facebook.com/1***5/picture"}}]}]}

AngularJS Controller for Auth (navCtrl):

  $scope.signedIn = Auth.isAuthenticated;

  $scope.logout = Auth.logout;

  Auth.currentUser().then(function(user){
    $scope.user = user;
  });

  $scope.$on('devise:new-registration', function (e, user){
    $scope.user = user;
  });

  $scope.$on('devise:login', function (e, user){
    $scope.user = user;
  });

  $scope. $on('devise:logout', function (e, user){
    $scope.user = {};
  });

I have also opened a question on stackoverflow:
http://stackoverflow.com/questions/33418651/angular-devise-not-working-properly-with-userserializer-active-model-serializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant