Skip to content

Add public config #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2021

Conversation

thecoolwinter
Copy link
Contributor

What kind of change does this PR introduce?

  • Makes PostgrestClient config options public, and puts them in a separate struct for a simpler API.
  • Adds an init method to the PostgrestClient for initalizing with a config object.
  • Fixes test cases (add Content-Type header to all requests)

This change is mostly to make the headers, url and schema public variables, but I've moved them into their own struct to make the public client API less confusing with lots of public variables.

What is the current behavior?

Right now PostgrestClient's config variables are private from outside the module, this becomes an issue when dealing with Auth, as the headers aren't mutable. This PR changes that by making the config variables mutable and public.

  • test cases were broken after the last PR that added the ContentType application/json header to all requests

What is the new behavior?

// Config object
let config = PostgrestClientConfig(url: "abc.supabase.io",
                                            headers: ["apikey": "1234"],
                                            schema: nil)

// New initalizer
let client = PostgrestClient(config)

// Modify the auth header
client.config.headers["Authorization"] = "Bearer: 12345" // now using bearer token auth for requests

// Modify the url
client.config.url = "123.supabse.io"

@thecoolwinter
Copy link
Contributor Author

If this config API is okay I'm hoping to make a similar change on the storage-swift repo. I'm hoping to add the ability to listen to auth state changes from the main Supabase client in supabase-swift, but to do that the headers must be public.

Copy link
Contributor

@grdsdev grdsdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@grdsdev grdsdev merged commit 7462c72 into supabase-community:master Sep 3, 2021
@thecoolwinter thecoolwinter deleted the add-public-config branch December 1, 2021 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants