B2B Saas Authentication

/

SDKs

/

React Native SDK reference

/

Members

Member

Once a Member has successfully logged in, the SDK can be used to view and manage that Member's information along with information about the Organization they belong to. In addition, the Member may create, update, and delete other Members in the Organization if their Role gives them permissions to do so. To learn more about our RBAC implementation, see our RBAC guide.

Methods

Get Member

The SDK provides synchronous and asynchronous methods for getting a Member. The recommended approach is to use the synchronous method, member.getSync, and listen to changes with the member.onChange method.

If logged in, the member.getSync method returns the cached Member object. Otherwise it returns null. This method does not refresh the Member's data.

The member.getInfo method is similar to member.getSync, but it returns an object containing the member object and a fromCache boolean. If fromCache is true, the Member object is from the cache and a state refresh is in progress.

The member.onChange method takes in a callback that gets called whenever the Member object changes. It returns an unsubscribe method for you to call when you no longer want to listen for such changes.

The @stytch/react-native library also provides the useStytchMember hook that implements these methods for you to easily access the Member and listen for changes.

The asynchronous method, member.get, wraps the search member endpoint. It fetches the Member's data and refreshes the cached object if changes are detected. The Stytch SDK will invoke this method automatically in the background, so you probably won't need to call this method directly.

import React from 'react';
import { Text } from 'react-native';
import { useStytchMember } from '@stytch/react-native/b2b';

export const Home = () => {
  const { member } = useStytchMember();

  return member ? <Text>Welcome, {member.name}</Text> : <Text>Log in to continue!</Text>;
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Create a Member

The Create Member method wraps the Create Member API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to create Members in other Organizations.


Method parameters


email_address*string

namestring

untrusted_metadataobject

create_member_as_pendingboolean

is_breakglassboolean

mfa_phone_numberstring

mfa_enrolledboolean

rolesarray[strings]
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const CreateMember = () => {
  const stytch = useStytchB2BClient();

  const createMember = () => {
    stytch.organization.members.create({
      email_address: 'sandbox@stytch.com',
    });
  };

  return (
    <View>
      <TouchableOpacity onPress={createMember}>
        <Text>Create a Member</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Update a Member

The Update Member method wraps the Update Member API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method can be used to update any Member in the logged-in Member's Organization.

Use the Update Self method when when the Member is deleting their own password.


Method parameters


member_id*string

email_addressstring

namestring

untrusted_metadataobject

is_breakglassboolean

mfa_phone_numberstring

mfa_enrolledboolean

default_mfa_methodstring

rolesarray[strings]
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const UpdateMemberName = () => {
  const stytch = useStytchB2BClient();

  const updateMemberName = () => {
    stytch.organization.members.update({
      member_id: 'member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f$',
      name: 'Jane Doe',
    });
  };

  return (
    <View>
      <TouchableOpacity onPress={updateMemberName}>
        <Text>Update Member name</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Search Members

The Search Members method wraps the Search Members API endpoint. It can be used to search for Members within the logged-in Member's Organization.

Submitting an empty query returns all non-deleted Members within the logged-in Member's Organization.

*All fuzzy search filters require a minimum of three characters.


Method parameters


cursorstring

limitint

queryobject
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const SearchMembers = () => {
  const stytch = useStytchB2BClient();

  const searchMembers = () => {
    stytch.organization.members.search({
      query: { operands: [{ filter_name: 'member_password_exists', filter_value: true }], operator: 'AND' },
    });
  };

  return (
    <View>
      <TouchableOpacity onPress={searchMembers}>
        <Text>Search Members</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "results_metadata": {
		"next_cursor": null,
		"total": 5
	},
  "members": [
    ...
  ]
  "organizations": <
    ...
  >
}

Delete Member

The Delete Member method wraps the delete member API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to delete Members in other Organizations.


Method parameters


member_id*string
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteMember = () => {
  const stytch = useStytchB2BClient();

  const deleteMember = () => {
    stytch.organization.members.delete('member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f');
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMember}>
        <Text>Delete Member</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f"
}

Reactivate a Member

The Reactivate Member method wraps the Reactivate Member API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to reactivate Members in other Organizations.


Method parameters


member_id*string
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const ReactivateMember = () => {
  const stytch = useStytchB2BClient();

  const reactivateMember = () => {
    stytch.organization.members.reactivate('member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f');
  };

  return (
    <View>
      <TouchableOpacity onPress={reactivateMember}>
        <Text>Reactivate Member</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Delete Member password

The Delete Member password method wraps the Delete Member password API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to delete the passwords of Members in other Organizations.

Use the Delete Self Password method when when the Member is deleting their own password.


Method parameters


member_password_id*string
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeletePassword = () => {
  const stytch = useStytchB2BClient();

  const deletePassword = () => {
    stytch.organization.members.deletePassword('member-password-test-51861cbc-d3b9-428b-9761-227f5fb12be9');
  };

  return (
    <View>
      <TouchableOpacity onPress={deletePassword}>
        <Text>Delete Password</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Delete Member MFA phone number

The Delete Member MFA phone number method wraps the Delete Member MFA phone number API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to delete the phone numbers of Members in other Organizations.

To change a Member's phone number, you must first call this endpoint to delete the existing phone number.

Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is deleted, and MFA will not be enforced until the Member logs in again. If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter a new phone number and calling the SMS OTP send endpoint, then calling the SMS Authenticate endpoint.

Use the Delete Self MFA Phone method when the Member is deleting their own TOTP MFA.


Method parameters


member_id*string
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteMemberMFAPhoneNumber = () => {
  const stytch = useStytchB2BClient();

  const deleteMemberMFAPhoneNumber = () => {
    stytch.organization.members.deleteMFAPhoneNumber('member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f');
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMemberMFAPhoneNumber}>
        <Text>Delete Phone Number</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Delete Member TOTP

The Delete Member TOTP method wraps the Delete Member TOTP API endpoint. The organization_id will be automatically inferred from the logged-in Member's session. This method cannot be used to delete totps of Members in other Organizations.

To change a Member's TOTP, you must first call this endpoint to delete the existing TOTP.

Existing Member Sessions that include a TOTP authentication factor will not be revoked if the TOTP is deleted, and MFA will not be enforced until the Member logs in again. If you wish to enforce MFA immediately after a TOTP is deleted, you can do so by prompting the Member to create a TOTP and calling the Create TOTP endpoint, then calling the TOTP Authenticate endpoint.

Use the Delete Self MFA TOTP method when when the Member is deleting their own TOTP MFA.


Method parameters


member_id*string
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteMFATOTP = () => {
  const stytch = useStytchB2BClient();

  const deleteMFATOTP = () => {
    stytch.organization.members.deleteMFATOTP('member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f');
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMFATOTP}>
        <Text>Delete TOTP</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Update Self

The Update Self method wraps the Update Member API endpoint. The organization_id and member_id will be automatically inferred from the logged-in Member's session. This method can be used to update only the logged-in Member.

You can listen for successful Member updates anywhere in the codebase with the stytch.organization.onMemberChange() method or useStytchMember hook.


Method parameters


namestring

untrusted_metadataobject

mfa_phone_numberstring

mfa_enrolledboolean

default_mfa_methodstring
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const UpdateName = () => {
  const stytch = useStytchB2BClient();

  const updateName = () => {
    stytch.self.update({
      name: 'Jane Doe',
    });
  };

  return (
    <View>
      <TouchableOpacity onPress={updateName}>
        <Text>Update name</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Delete Self password

The Delete Self password method wraps the Delete Member password API endpoint. The organization_id and member_id will be automatically inferred from the logged-in Member's session. This method can only be used to delete the logged-in Member's password.

import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeletePassword = () => {
  const stytch = useStytchB2BClient();

  const deletePassword = () => {
    stytch.self.deletePassword('member-password-test-51861cbc-d3b9-428b-9761-227f5fb12be9');
  };

  return (
    <View>
      <TouchableOpacity onPress={deletePassword}>
        <Text>Delete Password</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Delete Self MFA phone number

The Delete Self MFA phone number method wraps the Delete Member MFA phone number API endpoint. The organization_id and member_id will be automatically inferred from the logged-in Member's session. This method can only be used to delete the logged-in Member's MFA phone number.

To change a Member's phone number, you must first call this endpoint to delete the existing phone number.

Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is deleted, and MFA will not be enforced until the Member logs in again. If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter a new phone number and calling the SMS OTP send endpoint, then calling the SMS Authenticate endpoint.

You can listen for successful Member updates anywhere in the codebase with the stytch.organization.onMemberChange() method or useStytchMember hook.

import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteMFAPhoneNumber = () => {
  const stytch = useStytchB2BClient();

  const deleteMFAPhoneNumber = () => {
    stytch.self.deleteMFAPhoneNumber();
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMFAPhoneNumber}>
        <Text>Delete Phone Number</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Delete Self MFA TOTP

The Delete Self MFA totp method wraps the Delete Member MFA TOTP API endpoint. The organization_id and member_id will be automatically inferred from the logged-in Member's session. This method can only be used to delete the logged-in Member's MFA totp.

To change a Member's totp, you must first call this endpoint to delete the existing totp.

Existing Member Sessions that include a TOTP authentication factor will not be revoked if the TOTP is deleted, and MFA will not be enforced until the Member logs in again. If you wish to enforce MFA immediately after a TOTP is deleted, you can do so by prompting the Member to create a new TOTP and calling the TOTP create endpoint, then calling the TOTP Authenticate endpoint.

You can listen for successful Member updates anywhere in the codebase with the stytch.organization.onMemberChange() method or useStytchMember hook.

import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteMFATOTP = () => {
  const stytch = useStytchB2BClient();

  const deleteMFATOTP = () => {
    stytch.self.deleteMFATOTP();
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMFATOTP}>
        <Text>Delete MFA TOTP</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}

Update Member (Deprecated)

This method is deprecated. Please use the Update Self method to update the logged-in Member, or use the new Update Member method to update other Members.

The Update Member method wraps the Update Member API endpoint. Use this method to update the Member's name, untrusted metadata, MFA phone number, and MFA enrollment status.

You can listen for successful Member updates anywhere in the codebase with the stytch.organization.onMemberChange() method or useStytchMember hook.


Method parameters


namestring

untrusted_metadataobject

mfa_phone_numberstring

mfa_enrolledboolean
import React, { useCallback } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react/b2b';

export const UpdateMember = () => {
  const stytchClient = useStytchB2BClient();

  const updateName = useCallback(() => {
    stytchClient.member.update({
      name: 'Jane Doe',
      untrusted_metadata: {
        display_theme: 'DARK_MODE',
      },
    });
  }, [stytchClient]);

  return (
    <>
      <View>
        <TouchableOpacity onPress={updateName}>
          <Text>Update name</Text>
        </TouchableOpacity>
      </View>
    </>
  );
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "member": {...},
  "organization": {...}
}

Delete Member MFA phone number (Deprecated)

This method is deprecated. Please use the Delete Self MFA Phone Number method to update the logged-in Member's MFA phone number, or use the new Delete MFA Phone Number method to update other Members' MFA phone numbers.

The Delete Member MFA phone number method wraps the Delete Member MFA phone number API endpoint. Use this method to delete the Member's MFA phone number.

To change a Member's phone number, you must first call this endpoint to delete the existing phone number.

Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is deleted, and MFA will not be enforced until the Member logs in again. If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter a new phone number and calling the SMS OTP send endpoint, then calling the SMS Authenticate endpoint.

You can listen for successful Member updates anywhere in the codebase with the stytch.organization.onMemberChange() method or useStytchMember hook.

import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytchB2BClient } from '@stytch/react/b2b';

export const deleteMemberMFAPhoneNumber = () => {
  const stytchClient = useStytchB2BClient();

  const deleteMFAPhoneNumber = () => {
    stytchClient.member.deleteMFAPhoneNumber();
  };

  return (
    <View>
      <TouchableOpacity onPress={deleteMFAPhoneNumber}>
        <Text>Delete MFA phone number</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "member": {...},
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization": {...}
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "status_code": 200
}