Users
The users feature of Supaplate is intentionally minimalistic, different applications have different needs and requirements for their user profiles.
That is why the users profile table only has a name
, avatar_url
and marketing_consent
column.
You can extend the user profile by adding more columns to the profiles
table.
In this section we will learn how to configure the users feature of Supaplate so that your users can upload their profile pictures.
If your application does not require a profile picture, you can skip this section.
Creating a Supabase Storage bucket
Head over to Storage in the Supabase dashboard and click on the Create bucket
button.
Name it avatars
, turn on the Public
option and click on the Additional configuration
menu.
Turn on the Restrict file upload size for bucket
option and set the Max file size
to 1 MB
.
Then in the Allowed MIME types
input write image/*
and click on the Save
button.
Securing the bucket
Go to Storage policies and click on the Create policy
button in your 'avatars' bucket.
Click on For Full Customization
.
Add a name like avatars-policy
.
Then select all the operations (SELECT, INSERT, UPDATE, DELETE).
Select the 'authenticated' role, and finally copy paste the following policy in the 'Policy Definition' input:
(
(bucket_id = 'avatars'::text)
AND
storage.filename(name) = (auth.uid())::text
)
Click on the Save
button and you are all set.
This policy will only allow the authenticated user to upload and delete their own profile pictures and it will make sure that the file name is the same as the user's id, this way you don't have to worry about wasting storage space with multiple files.