User Management
How to manage your authenticated user in React Native
Get current user
Once your user has been authenticated, you can call Passage.currentUser.userInfo()
which will return a CurrentUser
object. When the user is no longer authenticated, this method will return null
.
Here's an example:
const user: <CurrentUser | null> = await passage.currentUser.userInfo()();
if (user) {
console.log(`User ID: ${user.id}`);
} else {
console.log('No authenticated user');
}
You can find all of the available properties on CurrentUser
Github.
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 message where they'll need to confirm the change.
// Change email for authenticated user
const newEmail = 'new@email.com';
await passage.currentUser.changeEmail(newEmail);
// Change phone for authenticated user
const newPhone = '155555555555';
await passage.currentUser.changePhone(newPhone);
Manage user passkeys
The following CRUD operations are available for authenticated user passkeys. Note that each of these methods could throw an error that you'd need to handle.
// List user's passkeys
const user = await passage.currentUser.userInfo();
const userPasskeys = await passage.currentUser.passkeys();
// Create a new passkey
const newPasskey = await passage.addPasskey();
// Edit name of passkey
const passkeyId = 'XXXXXXXXXXXXXX';
const passkeyNewName = 'My favorite passkey';
await passage.currentUser.editPasskey(passkeyId, passkeyNewName);
// Delete/revoke a passkey
await passage.currentUser.deletePasskey(passkeyId);
Sign out user
To sign out your user and remove their tokens from the user's device (more on this in the next section), you can simply call Passage.currentUser.logout()
.
await passage.currentUser.logout();