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

return custom json data after sign_in #567

Closed
sulmanweb opened this issue Mar 9, 2016 · 1 comment
Closed

return custom json data after sign_in #567

sulmanweb opened this issue Mar 9, 2016 · 1 comment

Comments

@sulmanweb
Copy link

First of all thanks Lynn for such a great gem.

Secondly, I want to override the return JSON after successful login. Please help me how? I have created dynamic authorization system with users. So I want to reply back the authorization structure of the user with the normal data after sign_in.

@sulmanweb
Copy link
Author

I solved it my-self.

First in config/routes.rb I added the custom sessions controller:

mount_devise_token_auth_for 'User', at: 'auth', skip: [:omniauth_callbacks], controllers: { registrations: "registrations", sessions: "sessions" }

Then created a file called app/controllers/sessions_controller.rb and added following content:

class SessionsController < DeviseTokenAuth::SessionsController
  def render_create_success
    render "users/success"
  end
end

Then I created a file named app/views/users/success.json.jbuilder and added the json data like this:

json.data @resource
json.groups @resource.groups do |group|
  json.id group.id
  json.name group.name
end

So by that I can give the custom JSON after successful login.

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