-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Custom Serializer like ActiveModel Serializer #249
Comments
Hi @stephenbaidu , did you find a way to do it? I'm looking for the same thing. |
FYI I only managed to do it by overriding the controllers, didn't find another way for now. |
@rentziass Still searching since I do not want to override the controller. |
@stephenbaidu, don't suppose you have any tips on that hack? I'm looking into the overrides right now and not seeing much help anywhere, docs or otherwise. A working example would be invaluable. :) |
@DeanSolecki I managed to get the response in the format I needed by overriding this: devise_token_auth/app/models/devise_token_auth/concerns/user.rb Lines 216 to 220 in c11dd18
That's just "to_jsoning" the resource, aka User, excluding some of the attributes. Nothing prevents you from replacing those lines with a serializer of yours. def token_validation_response
YourUserSerializer.new( self, root: false )
end |
@rentziass Thanks! This is exactly what I was looking for. :) |
@DeanSolecki No problem, I'm glad it helped, I spent hours trying to figure this out :) |
@rentziass Brilliant and thanks. |
I wrote it in User model, but it doest work, am i doing something wrong? class User < ActiveRecord::Base
include DeviseTokenAuth::Concerns::User
# Include default devise modules.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable
# Exclude: confirmable
validates_presence_of :name
def token_validation_response
UserSerializer.new( self, root: false )
end
end |
@AlexVKO I had success with: |
Thank you @juddey |
Does it still works? I can't make it work on my api.... |
Please close this. This is the preferred solution: https://github.com/lynndylanhurley/devise_token_auth#overriding-rendering-methods |
agree |
Preferred solution docs moved: |
Is there some easy way of forcing my custom serializer on the object I get at $auth.user? Apart from overriding the controller that is rendering and specifying the active model serializer class to use?.
The text was updated successfully, but these errors were encountered: