trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

sanitize_user breaks with associations #58

Closed ChrisMacNaughton closed 8 years ago

ChrisMacNaughton commented 9 years ago

My user model has multiple associations on it and apparently breaks in the SessionInteractor when trying to render JSON because the associations are not loaded. I would like a way to configure the attributes to send with the user instead of just removing a few attributes in the sanitize_user method.

trenpixster commented 9 years ago

While built-in support is not available, an alternative would be to override whatever modules are necessary to refactor. E.g., for the route /register you'd do something like this:

# YourController.ex
(...)
def register(conn, user_params) do
    {:ok, user} = Addict.ManagerInteractor.create(user_params)
    {conn, %{user: user}} = Addict.SessionInteractor.register({:ok, user}, conn)

    user = your_function_to_inject_associations(user)
    json conn, your_function_to_jsonify(user)
  end
(...)

#router.ex
(...)
    addict :routes,
      register: [controller: YourController, action: :register ]
(...)

Would something like this fix your issue?

trenpixster commented 8 years ago

Closing for now, please reopen if the issue still persists.