Skip to content

chore: Add custom headers from options in Client.cs #168

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
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Supabase/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ private void Auth_StateChanged(object sender, AuthState e)
/// <inheritdoc />
public Task<BaseResponse> Rpc(string procedureName, object? parameters) =>
_postgrest.Rpc(procedureName, parameters);

/// <inheritdoc />
public Task<TModeledResponse?> Rpc<TModeledResponse>(string procedureName, object? parameters) =>
_postgrest.Rpc<TModeledResponse>(procedureName, parameters);

/// <summary>
/// Produces dictionary of Headers that will be supplied to child clients.
///</summary>
internal Dictionary<string, string> GetAuthHeaders()
{
var headers = new Dictionary<string, string>
Expand All @@ -257,9 +260,7 @@ internal Dictionary<string, string> GetAuthHeaders()
};

if (_supabaseKey != null)
{
headers["apiKey"] = _supabaseKey;
}

// In Regard To: https://github.com/supabase/supabase-csharp/issues/5
if (_options.Headers.TryGetValue("Authorization", out var header))
Expand All @@ -272,7 +273,11 @@ internal Dictionary<string, string> GetAuthHeaders()
headers["Authorization"] = $"Bearer {bearer}";
}

// Add supplied headers from `ClientOptions` by developer
foreach (var kvp in _options.Headers)
headers[kvp.Key] = kvp.Value;

return headers;
}
}
}
}
Loading