aswinmohanme

aswinmohanme

Phx.gen.auth Where to add extra user information?

I have generated an auth system with phx.gen.auth . I need to add mroe information to the user such as stripe connect id and such. Should I add directly to the user schema or create a profile schema and attach it one to one to the user schema. If going through the profile route how can I make sure all my users have an associated profile with it.

Any pointers would be really helpful.

Marked As Solved

soup

soup

I think the general advice has become to separate “log in methods/credentials” from “user accounts”, because you can more easily manage user data and login data.

So you may end up with

user: id, name, email
web_login: user_id, hash, last_used, last_host, recovery_code
totp_login:  user_id, secret, last_used, last_host
oauth_login: user_id, token, ...
...

etc. Instead of ending up with really fat user tables.

It maybe depends on your desired complexity, but you don’t really lose much by normalising the database.

If you do stick them all in the single table, I would recommend creating different schemas for each login method so your modules are better focused. (You can define multiple schemas that point to one table and have each only include the pertinent fields.)

You can ensure your data has integrity with database constraints (see ecto constraint validation).

E: Sorry I may have been a bit unclear to your actual question, you can put stripe_connect_id in the users table, it really depends on how much you think you will end up stuffing in there and how much you want to normalise your dataset.

I personally structure my accounts like this:

users: id, email, hashed_password
users_roles: user_id, role_id
roles: id, type
profiles: user_id, name, avatar, ...

If I wanted to store a users stripe data (unfamiliar with the specifics of the API) I personally would put it in another table:

user_stripes: user_id, connect_id, account_name?, public_key?, ...

This means you can more easily expand to have a user own multiple stripe accounts, etc.

Also Liked

APB9785

APB9785

Creator of ECSx

phx.gen.auth already generates separate tables for users and user_tokens. OP should add the columns to the users table.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement