-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AdminAPI and deleteUser method
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// AuthAdmin.swift | ||
// | ||
// | ||
// Created by Guilherme Souza on 25/01/24. | ||
// | ||
|
||
import Foundation | ||
@_spi(Internal) import _Helpers | ||
|
||
public actor AuthAdmin { | ||
private var configuration: AuthClient.Configuration { | ||
Dependencies.current.value!.configuration | ||
} | ||
|
||
private var api: APIClient { | ||
Dependencies.current.value!.api | ||
} | ||
|
||
public init() {} | ||
|
||
/// Delete a user. Requires `service_role` key. | ||
/// - Parameter id: The id of the user you want to delete. | ||
/// - Parameter shouldSoftDelete: If true, then the user will be soft-deleted (setting | ||
/// `deleted_at` to the current timestamp and disabling their account while preserving their data) | ||
/// from the auth schema. | ||
/// | ||
/// - Warning: Never expose your `service_role` key on the client. | ||
@discardableResult | ||
public func deleteUser(id: String, shouldSoftDelete: Bool = true) async throws -> User { | ||
try await api.execute( | ||
Request( | ||
path: "/admin/users/\(id)", | ||
method: .delete, | ||
body: configuration.encoder.encode(DeleteUserRequest(shouldSoftDelete: shouldSoftDelete)) | ||
) | ||
) | ||
.decoded(decoder: configuration.decoder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters