Giter Site home page Giter Site logo

Comments (3)

danschultzer avatar danschultzer commented on May 3, 2024 1

You can extend the users context easily: https://github.com/danschultzer/pow/blob/master/lib/pow/ecto/context.ex#L7-L20

In this case I wouldn't combine the two, but instead just keep the default context methods inside Pow, and create one specifically for my manager actions. It's better to have different contexts depending on how you interact with the underlying user struct. But if you do wish to change or extend how the default context is working then the above docs is how you do it!

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

I wouldn't use any Pow methods, but instead create a context module for manager API calls. This can work better for security as you can limit that particular changeset to just accepting role changes.

This is one way of setting it up:

defmodule MyApp.UserManagement do
  alias MyApp.Users.User

  def update_role(user, attrs) do
    user
    |> User.role_changeset(attrs)
    |> Repo.update()
  end
end

defmodule MyApp.Users.User do
  # ...

  def role_changeset(user_or_changeset, attrs) do
    cast(user_or_changeset, attrs, [:role])
  end
end

Pow.Ecto.Context (that Pow.Operations uses by default) is the context API for handling registration and authentication with Pow, and just that. Any other kind of operations should be moved to a dedicated context.

from pow.

jung-hunsoo avatar jung-hunsoo commented on May 3, 2024

I agree. To create another context is easy and manageable. But I'd like to know if there's a flexible and configurable way to achieve this.

I believe this feature will be one of frequently requested by developers. If so, how about providing Myapp.Users context for better extensibility by default?

from pow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.