Best way to add social accounts to a person
I am working on a small app right now with NextJS that basically has 2 parts. There is a public/client facing landing page where information from the database will be displayed. The page will contain a basic message, contact information, and links to their social accounts.
The other part is an admin only page (registered supabase users) with a form for creating new clients.
I set up a table named "clients" that has all of the necessary columns (name, message, street, city) except for their social media links. I am a bit stuck on how to proceed with this at the moment. My first thought was to just have preset social columns in the table and have the form write directly to those. However, I am thinking I might run into some issue down the line where the I have not accounted for a type of account. Should I just use an array on varchar with objects, or is there a better way to go about this? I do apologize if this confusing. If any more clarification is needed please let me know!
3 Replies
Hmmm what I would do is probably have 3 tables....
1. Users ( you already have this )
2. Socials
-
id
: auto generated id
- name
: name of social like Discord, Twitter, Google, etc. )
- link
- the base link for each social, like Twitter.com/
3. User_Socials - connection table
- user
- FK pointing to your user_id
in the Users
table
- social
- FK pointing to a id
in Socials
- link
- link to the social, added to the base link. If your Twitter profile is Twitter.com/example
, then the user would need to populate this field with example
Then you can call User_Socials
and return all rows where user
matches, and then use the data in Socials
to populate the UI.
Because you have link
, which is just a base link for each social, you can build out the Ui easier I think.
There may be a better / easier way though. Usually when you think something "needs an array" ( like a list of items ), its better to build multiple tables that connect.
By the way, this might seem like a complicated API call, but it's not. Supabase has this really cool feature where you can get add a comma ,
in your call request and obtain the data from a table with a FK.
This is a snippet of a call I used with a similar setup. Notice how I added a ,
and was able to return all the relevant info in User_Socials
within a user
object.Thanks for the insight! I will give this a go in the morning and see how it all goes. I appreciate your help on this!
Sounds good ! keep an eye on this thread though so other people might have better solutions.