How to create/update user profile after successful Pow registration & login?

Hi all,
I have multiple roles to implement and I plan to have multiple tables to create/manage user profiles for each role.

Whats the best way to create a mapping between users table and other profile tables? Btw, I am using Pow for authentication. How do I create/update user profile(based on role) once registration/login is successful for the corresponding user? Does Pow provide any mechanism to manage profile info after successful registration/login?

Hi all, any inputs/suggestions on this? Whats the best way to handle user profiles and the relation with users table? Does Pow provide a mechanism to create/fetch/update user profile info based on current_user?

What I do is using Plugs.

The idea is when user get authenticated through the login page they will be redirected for example on a profile page (that you have to create yourself of course, but the following can works with the home page as well).

  • You need a Plug that ensures a profile exists for the current_user before accessing the above said page. If not, you redirect the user on a page where he will fill a form and complete his registration.
    I’m used to call this page controller MyApp.AccountController or MyApp.ProfileController. In fact I have often the both: the fisrt map to User schema and the last to Profile schema.

  • Now to load the profile into @current_user you can have a look to this reply that helped me.

I hope it helps a bit…

Thanks, Kurisu. I will check this out. However, I am using backend only for APIs. So, just wondering how to create/fetch/update user profile entry in database after Pow registration/login based on current_user. Also, I have multiple roles and how to link them to users table? Does Pow provide a way to handle this kind of scenario?

Unfortunately you’ll have to handle this on your own depending on your scenario.

There are some Pow guides that you may find useful though:

There is a thread I read long time ago on how to design user table and profile infos on the forum but I’m not finding it right now…

If I find it I will post it here. It was discussed many ways to store roles and account infos. For example One could even use an ecto migration :map type to store them in the user table but it is not perfomant if you’re planning running queries against it…

In my case what I do is just adding a profile table per role and keep a role field in the user table. But this works only because i have few roles and each user has just one role. So if I have for example the roles admin, client, author I will have the profile tables of the same names to store role specific infos. If a role does not need specific additionnal infos apart from the common infos stored in the user table I won’t create a profile table for it. If another table need a user with a specific role as reference to a foreign_key, I will also need a profile table. for example an author_id for a blog post.

For now at least this works for my projects needs…