coherence icon indicating copy to clipboard operation
coherence copied to clipboard

Support different kinds of users with Coherence

Open hrishikeshchoudhari opened this issue 8 years ago • 15 comments

For instance, one might need authentication for sellers and buyers.

Or admin, and author ?

hrishikeshchoudhari avatar Aug 27 '16 14:08 hrishikeshchoudhari

I think that should be delegated to Authorization like with Canary https://github.com/cpjk/canary

smpallen99 has some repos where he integrates it all, also check whatwasit with --whodoneit really awesome stuff with ExAdmin and Coherence, I need to put all the pieces together to do my own kind of wiki with admins staff and users.

agustif avatar Aug 27 '16 19:08 agustif

Yes I'm looking at Canary for handling authorization & privileges.

But I assumed Canary would come in the picture only after the user account is created.

With default Coherence, both sellers & buyers could get the same login/signup UI, and be put in the same users model. Can we add different models to Coherence?

hrishikeshchoudhari avatar Aug 28 '16 04:08 hrishikeshchoudhari

Coherence should already provide some limited support for multiple user models. Although I have not tested it directly on Coherence, the Session plug does have support for providing a db_model option. I created Coherence based on a previous designed I use on another project which has 2 separate user models.

You will need to create separate routes for each login, either in the same endpoint, or separate endpoints (my project used separate endpoints since the they used different databases). You will also need to a separate session controller, or adapt the current session controller to handle multiple use models.

As well a providing the db_model option to the session plug, you can also provide a login callback For example, assuming you have setup the default authorization for buyers and want to setup a second user model for sellers, you could do the following in your router:

        pipeline :browser_seller do
          plug :accepts, ["html"]
          # ...
          plug Coherence.Authentication.Session, db_model: MyProject.SellerUser
        end

        pipeline :protected_seller do
          plug :accepts, ["html"]
          # ...
          plug Coherence.Authentication.Session, db_model: MyProject.SellerUser, login: MyProject.SellerSessionController.login/2 
        end

I will look at adding full support for multiple user models when I get some time.

smpallen99 avatar Aug 28 '16 10:08 smpallen99

I'm actually embarking on this feature for my application today, because I have a frontend and a backend, with admins on the backend, and customers on the frontend.

Customers have additional fields in the database that an admin doesn't (for example address, shipping details, etc).

I'll document as I go.

joshuataylor avatar Aug 30 '16 03:08 joshuataylor

@joshuataylor Sounds great. Are you planning on submitting PR? If so, would be great to review design as you go.

smpallen99 avatar Aug 30 '16 13:08 smpallen99

any updates on this?

cubeguerrero avatar Mar 01 '17 13:03 cubeguerrero

Im interested on this too, I want to build a Admin/Seller/Customer interface and with all the new shit going on with phx1.3 and ex1.4 I don't know where to start. Ffs, I can't even get basic Ecto belongs_to <> has_many right...

agustif avatar Apr 17 '17 22:04 agustif

I'm going to need this in about a week too. So, expect an update soon.

smpallen99 avatar Apr 17 '17 22:04 smpallen99

Great @smpallen99 , I will be following along the repos...

Anyways, I don't want to nitpick, but have you taken a look at rummage-phoenix? it seems it solves doing a lot of the functionality desired from exadmin dashboards with much less boilerplate/input fields/ui noise

I don't know, I just like how sorting and filtering/search works, but not sure if could be added easily.

Thanks for all your open source elixir projects, you rock!

agustif avatar Apr 18 '17 02:04 agustif

Hey @smpallen99 any updates on this? I'm trying to setup multiple user models in an umbrella application and I'm concerned that since coherence uses cookies to identify a logged in user, it maybe over-written / interchanged with the wrong user model.

dsignr avatar Jul 14 '17 18:07 dsignr

@dsignr No updates yet. I have some WIP done for refactor that would allow namespaced coherence configuration. The driver for this is mainly to support coherence in umbrella apps. However, it would also allow multiple coherence schemas. However, I have not had time in the last few weeks to complete the refactor.

And now that Phoenix 1.3 has been released, with some major changes over the the previous rc's, I have more work to do just to properly support this latest release :(

smpallen99 avatar Jul 30 '17 19:07 smpallen99

Has anyone made any progress on this or have any examples of how this might be implemented with canary?

xanderseren avatar Dec 13 '17 20:12 xanderseren

I would also be interested in something like this?

isAlmogK avatar Apr 20 '18 01:04 isAlmogK

Any updates on this?

guilpejon avatar Aug 26 '18 00:08 guilpejon

@smpallen99 are you still planning to implement this?

besniksh95 avatar Feb 15 '19 09:02 besniksh95