User Management

How to manage your authenticated user in your Swift app

Get user

Once your user has been authenticated, you can call passage.currentUser.userInfo() which will return a CurrentUser struct. When the user is no longer authenticated, this method will throw an error.

Here's an example:

let passage = Passage(appId: "YOUR_APP_ID")
let userInfo = try? await passage.currentUser.userInfo()

Methods for updating user

Change contact info

To change the user's phone number or email, you can follow the examples below. Note that the user will receive a verification email or text message where they'll need to confirm the change.

// Change email for authenticated user
try? await passage.currentUser.changeEmail(newEmail: "new@email.com");
 
// Change phone for authenticated user
try? await passage.currentUser.changePhone(newPhone: "155555555555");

Manage user passkeys

The following CRUD operations are available for user device passkey credentials:

// Create a new device passkey
try? await passage.currentUser.addPasskey()
 
// Get user's device passkeys
let passkeys = try? await passage.currentUser.passkeys()
 
// Edit a device passkey name
let passkeyId = "XXXXXXXXXXXXXX"
let newName = "My favorite passkey"
try? await passage.currentUser.editPasskey(passkeyId: passkeyId, newFriendlyName: newName)
 
// Revoke a device passkey
// NOTE: This does NOT remove the passkey from the user's device, but it revokes the passkey
try? await passage.currenUser.deletePasskey(passkeyId: id)

Log out user

To log out your user and remove their tokens from the TokenStore (more on this in the next section), you can simply call passage.logOut() .

try? await passage.currentUser.logOut()