Skip to content

Allow GoTrueClient injectable to SupabaseClient initializer #69

Closed
@kurtguenther

Description

@kurtguenther

Feature request

It would be great a GoTrueClient to be injected as a parameter to SupabaseClient initializer.

Is your feature request related to a problem? Please describe.

We have a specific Keychain configuration that we need to inject to the GoTrueClient (whose initializers already support injecting their own KeychainStorage/GoTrueLocalStorage. Our app will not be able to use the defacto Keychain location that is being provided in the GoTrueClient(...) init that this initializer is using.

Describe the solution you'd like

This could be as easy as allowing a new constructor

  public init(
    supabaseURL: URL,
    supabaseKey: String,
    schema: String = "public",
    headers: [String: String] = [:],
    httpClient: HTTPClient = HTTPClient(),
    authClient: GoTrueClient
  ) {

It seems that the auth client does depend on the headers, so maybe allowing some kind of convenience method on GoTrueClient(...) to construct it based upon the existing supabaseURL and supabaseKey which are added via the defaultHeaders property, would be helpful.

Describe alternatives you've considered

Instead of being provided to the initializer, the auth property could become a var for an automatic get or there could be another function like setAuthClient(...) that is exposed. But that would probably introduce some weird conditions that are tougher to reason about rather than just injecting in the init(...)

Additional Context

If either approach is acceptable, I'm happy to write it up and put up a PR.
Thanks.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions