Skip to content

Conversation

@valt-x
Copy link
Contributor

@valt-x valt-x commented Dec 1, 2025

Adds update_auth/2 and :auth option for invoke/3 to support token rotation like JS client's setAuth(). Closes #3

Adds update_auth/2 and :auth option for invoke/3 to support token rotation like JS client's setAuth(). Closes supabase-community#3
Comment on lines +132 to +135
case opts[:auth] do
nil -> client
auth_token when is_binary(auth_token) -> update_auth(client, auth_token)
end
Copy link
Member

Choose a reason for hiding this comment

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

for only 2 logic branches, i would go with a simpler if/2, so we can follow the rest of project standard

timeout = opts[:timeout] || 15_000

client
# Handle auth token override
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Handle auth token override

Comment on lines +158 to +164
### Benefits

- **Token rotation support**: Easily update tokens without recreating clients
- **Better performance**: Avoid the overhead of creating new client instances
- **Flexibility**: Use different tokens per request or update client globally
- **Feature parity**: Matches the JavaScript client's `setAuth()` functionality
- **Immutability**: Original client instances remain unchanged with functional updates
Copy link
Member

Choose a reason for hiding this comment

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

i don't think this kind of content fits well on a README

Suggested change
### Benefits
- **Token rotation support**: Easily update tokens without recreating clients
- **Better performance**: Avoid the overhead of creating new client instances
- **Flexibility**: Use different tokens per request or update client globally
- **Feature parity**: Matches the JavaScript client's `setAuth()` functionality
- **Immutability**: Original client instances remain unchanged with functional updates

- **Comprehensive timeout coverage**: Sets both receive timeout (per-chunk) and request timeout (complete response)
- **Feature parity with JS client**: Matches timeout functionality in the JavaScript SDK

## Dynamic Auth Token Updates
Copy link
Member

Choose a reason for hiding this comment

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

this section at all seems not to fit on a README file

- **Request cancellation**: Long-running requests will timeout and be cancelled
- **Better resource management**: Prevents hanging connections
- **Comprehensive timeout coverage**: Sets both receive timeout (per-chunk) and request timeout (complete response)
- **Feature parity with JS client**: Matches timeout functionality in the JavaScript SDK
Copy link
Member

Choose a reason for hiding this comment

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

existing section i know, but isn't necessary to explicit say we have feature parity with JS, this is implicit

| {:region, region}
| {:on_response, on_response}
| {:timeout, pos_integer()}
| {:auth, String.t()}
Copy link
Member

Choose a reason for hiding this comment

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

JS uses auth as the override token option key? maybe we could think on something like access_token or authorization_token, wdyt?

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.

Add dynamic auth token updates

2 participants