Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Administrar usuarios

Create and Delete Users - Swift SDK

Para la mayoría Métodos de autenticación: Atlas App Services crea automáticamente un objeto de usuario la primera vez que un usuario se autentica. La única excepción es la autenticación por correo electrónico y contraseña. Al usar esta autenticación, debe registrar y confirmar al usuario antes de que pueda autenticarse en una aplicación de App Services.

Tip

Apple Account Deletion Requirements

New in version 10.23.0.

You can call the delete method on a user object to delete the user object from your App. This deletes the object from the server in addition to clearing local data.

Importante

Al eliminar un usuario, solo se elimina el objeto de usuario, que puede contener metadatos asociados. Esto no borra los datos personalizados de usuario ni los datos ingresados por el usuario en tu aplicación. Apple requiere que informes políticas sobre retención y eliminación de datos a los clientes de tu aplicación y que les brindes una forma de solicitar la eliminación de datos de usuario. Si recopilas datos adicionales de usuarios, debes implementar tus propios métodos o procesos para borrar esos datos.

Si su aplicación utiliza la sintaxis async/await de Apple:

func testAsyncDeleteUser() async throws {
// Logging in using anonymous authentication creates a user object
let syncUser = try await app.login(credentials: Credentials.anonymous)
// Now we have a user, and the total users in the app = 1
XCTAssertNotNil(syncUser)
XCTAssertEqual(app.allUsers.count, 1)
// Call the `delete` method to delete the user
try await syncUser.delete()
// When you delete the user, the SyncSession is destroyed and
// there is no current user.
XCTAssertNil(app.currentUser)
// Now that we've deleted the user, the app has no users.
XCTAssertEqual(app.allUsers.count, 0)
}

Starting with Realm Swift SDK Versions 10.15.0 and 10.16.0, many of the Realm APIs support the Swift async/await syntax. Projects must meet these requirements:

Versión del SDK de Swift
Swift Version Requirement
Supported OS

10.25.0

Swift 5.6

iOS 13.x

10.15.0 o 10.16.0

Swift 5.5

iOS 15.x

Si su aplicación accede a Realm en un async/await contexto, marque el código con @MainActor para evitar fallas relacionadas con subprocesos.

If your application does not use async/await:

// Logging in using anonymous authentication creates a user object
app.login(credentials: Credentials.anonymous) { [self] (result) in
switch result {
case .failure(let error):
fatalError("Login failed: \(error.localizedDescription)")
case .success(let user):
// Assign the user object to a variable to demonstrate user deletion
syncUser = user
}
}
// Later, after the user is loggedd in we have a user,
// and the total users in the app = 1
XCTAssertNotNil(syncUser)
XCTAssertEqual(app.allUsers.count, 1)
// Call the `delete` method to delete the user
syncUser!.delete { (error) in
XCTAssertNil(error)
}
// When you delete the user, the SyncSession is destroyed and
// there is no current user.
XCTAssertNil(app.currentUser)
// Now that we've deleted the user, the app has no users.
XCTAssertEqual(app.allUsers.count, 0)

Volver

Administrar usuarios

En esta página