supabase / supabase-swift

A Swift client for Supabase
https://supabase.com/docs/reference/swift
MIT License
684 stars 100 forks source link

No ListUsers method exists in the Auth Admin functionality #529

Open danperks opened 5 days ago

danperks commented 5 days ago

Feel free to close this if this is more of a feature suggestion, although arguably I could see it being considered a "bug" or an oversight, depending on if this was a conscious decision or not.

In the JS library, which the Swift library is meant to somewhaty mirror, there is a method called ListUsers defined here that enables the client to get all the users within their database, given the correct permissions to allow such a query.

As its not possible to directly query the "auth" schema for (valid) security reasons, this would be a simple and easy option, but it doesn't appear to have made it into the Swift library.

While a workaround for this would be to make a Postgres function to pull the data and pass it through, ideally my use case wouldn't require such an "install" process, being able to pull the list with only the instance URL and a key with the necessary permissions.

Is there any reason why the function wasn't included in the library? If so, is there any good workaround that doesn't require any changes to my Supabase instance. My next best idea is cloning the logic of the JS library method, which involves manually requesting the endpoint myself outside of the Swift library.

Thanks in advanced and keep up the good work 👍🏻

dshukertjr commented 2 days ago

The listUsers method is meant to be called on the server side, but are you using Swift on your backend code?

danperks commented 2 days ago

No, I hope to use the Swift client inside a client-side iOS app, as I'm making an management app for our team to use, while trying to avoid the need for a "proxy" server due to the architecture we are trying to deploy - each user has a local Supabase instance, which I want them to be able to manage via a Swift app.

dshukertjr commented 2 days ago

Cool, in that case, why do you feel that you need to use the listUsers method?

You can get the currently signed in user with the following method:

let user = try await supabase.auth.user()
danperks commented 2 days ago

Maybe I wasn't clear, sorry. To avoid explaining my use case directly, in essence, each user has a Supabase instance they are setting up and managing. In that, they will make some kind of app, powered by Supabase.

I want to make an iOS app that they can use to manage their database, by providing (ideally) their Supabase URL and the service_key. In the app, they will be able to see all the users as well as list and view the tables.

My current though is that I may have to go down the route of having them directly connect to the Postgres database, as the REST API seems to not support the features I need (list all users, query the db schema, etc), but doing that in Swift is not quite as simple as using the Supabase client lib for Swift instead.

If this is outside of the scope of this library, feel free to close the issue :)

dshukertjr commented 2 days ago

@danperks Thanks for the detailed explanations.

If this is outside of the scope of this library, feel free to close the issue :)

So the particular use case where the client accesses the Supabase database via the service role key is actually out of scope, but I know there are some, probably a very few, folks who use Swift on the serverside, so I'm going to leave the decision of whether to add listUsers method to this library or not to @grdsdev . He is on leave at the moment, but he will take a look at this issue once he is back.