upsert method
- required AiProvider provider,
- String? apiKey,
- String? model,
- AiAuthMode authMode = AiAuthMode.apiKey,
- String? oauthTokenId,
Upsert a row for (currentUser, provider). Caller is responsible for
having recorded consent first via recordConsent.
Implementation
Future<void> upsert({
required AiProvider provider,
String? apiKey,
String? model,
AiAuthMode authMode = AiAuthMode.apiKey,
String? oauthTokenId,
}) async {
final userId = _client.auth.currentUser?.id;
if (userId == null) {
throw StateError('Cannot save AI settings: not signed in.');
}
await _client.from('user_ai_settings').upsert({
'user_id': userId,
'provider': provider.name,
'api_key': apiKey,
'model': model,
'auth_mode': authMode == AiAuthMode.oauth ? 'oauth' : 'apiKey',
'oauth_token_id': oauthTokenId,
}, onConflict: 'user_id,provider');
}