Skip to content

Commit

Permalink
feat: add linkIdToken method to HasuraAuthClient
Browse files Browse the repository at this point in the history
  • Loading branch information
onehassan committed Nov 14, 2024
1 parent 6a84a3b commit e09dccc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/nhost_auth_dart/lib/src/auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,34 @@ class NhostAuthClient implements HasuraAuthClient {
}
}

/// Links an existing user account to a third-party provider using an OpenID Connect [idToken].
///
/// This method enables linking a user account with an OpenID Connect [idToken] from a specified
/// [provider], such as "google" or "apple". You can optionally provide a [nonce] for enhanced security.
///
/// Throws an [NhostException] if the link attempt fails.
@override
Future<void> linkIdToken({
required String provider,
required String idToken,
String? nonce,
}) async {
try {
await _apiClient.post<String>(
'/link/idtoken',
jsonBody: {
'provider': provider,
'idToken': idToken,
if (nonce != null) 'nonce': nonce,
},
headers: _session.authenticationHeaders,
);
} on NhostException catch (e) {
throw AuthServiceException(
'Failed to link account with provider $provider');
}
}

/// Signs in a user with a magic link.
///
/// An email will be sent to the [email] with a link. When the user
Expand Down
3 changes: 3 additions & 0 deletions packages/nhost_sdk/lib/src/base/hasura_auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ abstract class HasuraAuthClient {
Future<AuthResponse> signInIdToken(
{required String provider, required String idToken, String? nonce});

Future<void> linkIdToken(
{required String provider, required String idToken, String? nonce});

Future<void> signInWithEmailPasswordless(
String email, {
String? redirectTo,
Expand Down

0 comments on commit e09dccc

Please sign in to comment.