Comments (19)
workaround:
Before deleting a user, delete all files using the supabase client.
const deleteAllUsers = async () => {
const {
data: { users },
} = await client.auth.admin.listUsers();
for (let user of users) {
const directory = `users/${user.id}`;
const fileRes = await client.storage.from("images").list(directory);
for (let file of fileRes?.data ?? []) {
console.log({ file });
await client.storage.from("images").remove([`${directory}/${file.name}`]);
}
const { error } = await client.auth.admin.deleteUser(user.id);
if (error) {
console.log(`client.auth.admin.deleteUser(${user.id}) failed.`, {
error,
});
throw new Error(error.message);
}
}
};
from storage.
In my case, I want to delete all objects(photos uploaded by a user) when the user is deleted.
So I fixed storage.objects table's owner column Cascade.
Now, user and objects can be deleted without error.
from storage.
Hi @inian
As I understand, the solution to this is to add this SQL
drop constraint objects_owner_fkey,
add constraint objects_owner_fkey
foreign key (owner)
references auth.users(id)
on delete set null;
Is that correct?
Additionally, can you share some insight into what is going on behind the scenes to create this restriction, and why it is in place?
from storage.
I believe the idea here is that they don't want to delete the row because then the file will forever be stored without any reference. Until they have a proper way of handling deleting files as well on user deleted I don't think this will come anytime soon.
from storage.
Thats a good point Jian. I will add a trigger to make the owner as null in storage.objects when a row is deleted from auth.users.
from storage.
Also as a side question, is it a good idea or good practice to run our own migrations on the auth
and storage
schemas?
from storage.
good practice to run our own migrations on the auth and storage schemas
No - it would not be a good idea to modify the auth
or storage
schema. If you need to extend the functionality it would be best to add your own schemas. (and you can create views if you want to "join" schemas)
from storage.
I believe the idea here is that they don't want to delete the row because then the file will forever be stored without any reference. Until they have a proper way of handling deleting files as well on user deleted I don't think this will come anytime soon.
If we use set null
instead of cascade
, the database will still maintain a reference to the underlying S3 object though. Would that be sufficient?
from storage.
good practice to run our own migrations on the auth and storage schemas
No - it would not be a good idea to modify the
auth
orstorage
schema. If you need to extend the functionality it would be best to add your own schemas. (and you can create views if you want to "join" schemas)
Then, what would be the recommended practice here? I can't delete all objects uploaded by the user to storage before deleting the user because some of the objects still have to be retained after a user deletion.
For example, user Z uploads an avatar image for his team and later deletes his account. In this scenario, we would expect that deleting user Z wouldn't also delete the avatar image he uploaded.
from storage.
I haven't tested it out on an actual project but that does seem like it would work @mcewen87. The constraint is in place so that each storage owner is linked to an auth user and cos owner field shouldn't be any UUID.
from storage.
I haven't tested it out on an actual project but that does seem like it would work @mcewen87. The constraint is in place so that each storage owner is linked to an auth user and cos owner field shouldn't be any UUID.
Thank you! I'll give it a try.
from storage.
On my side, I had a "users" table with constraint users_id_fkey between my stripe table and "auth.users" table.
I simply added :
alter table users drop constraint users_id_fkey, add constraint users_id_fkey foreign key (id) references auth.users(id) on delete cascade;
from storage.
Feel free to re-open when providing more info
from storage.
Feel free to re-open when providing more info
Why would this need more info? You cannot delete a user from auth if they have records associated in the objects table. It is a bit of a pain.
from storage.
Faced the same issue today, didn't help that when I tried to delete a user through the UI (inside the Authentication tab), the error message was: "Failed to delete user: Failed to delete user". Only stumbled upon the actual error when I tried deleting the user through the SQL editor.
from storage.
An example of this problem in production for us was when employees of a business updated image content within the application. However, we did not realize that the authentication object associated with the employee would become bound to that image asset, making it impossible to delete the authentication user afterwards. Although we were able to work around this issue, it would be helpful to have more control over this relationship when uploading assets, especially since we updated some signup logic.
from storage.
@kiwicopple @fenos We face the same issue. Since this is still open, what is your recommended best practice if we want to delete a user but keep their uploaded objects?
from storage.
I got the same issue now, after hours of debugging and testing every possible way, this ended up working:
-
Set correct RLS Policies
-
Voila! 🥳
from storage.
We have removed the FK constraint now and we have a new column called owner_id
and owner
column is deprecated
from storage.
Related Issues (20)
- self-host storage got relation "buckets" does not exist thought schema and tables already exists HOT 9
- API link in readme here is outdated. HOT 1
- Storage RLS UPDATE WITH CHECK evaluates old data, not new HOT 4
- Can't upload files to storage HOT 3
- File upload is not possible when using custom roles HOT 1
- 410 on Head request from TUS client (uppy) to resumable endpoint HOT 1
- 5-10% of Uppy/TUS uploads fail HOT 8
- Can not integrate Lock Objects S3 with Supabase HOT 3
- Can't update files after migration HOT 5
- UNEXPECTED BEHAVIOR 'move' method HOT 1
- Move set owner to null HOT 1
- FFmpeg/FFprobe 'moov atom not found' Error When Processing Videos from Local Supabase Instance HOT 2
- Storage API changing file name HOT 1
- `move`, `copy` do not returning new file id HOT 4
- Add `file_metadata` field to objects schema HOT 30
- Rest Api For Storage Questions/Suggestions HOT 2
- Storage Upload Error Typescript Issue
- The values of both column `owner` and `owner_id` are set to `NULL` after calling `StorageFileApi` method `move`. HOT 1
- Private bucket files become public HOT 2
- How to set file owner on TUS upload HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storage.