Skip to main content
import { StytchB2BClient } from '@stytch/vanilla-js/b2b';

const stytch = new StytchB2BClient('public-token-test-b8c84de4-7d58-4ffc-9341-432b56596862');

// Parse token from URL
const parsed = stytch.parseAuthenticateUrl();

// Reset discovery password
if (parsed?.token) {
  const resetPassword = async (newPassword) => {
    const response = await stytch.passwords.discovery.resetByEmail({
      password_reset_token: parsed.token,
      password: newPassword,
    });
    console.log('Password reset:', response);
  };

  resetPassword('newSecurePassword123');
}
passwords.discovery.resetByEmail wraps the Reset By Email Discovery Password API endpoint. This endpoint resets the password associated with an email and starts an intermediate session for the user. If there is a current , the SDK will call the endpoint with the session token. This will add the new factor to the existing Member Session. If there is an token, the SDK will call the endpoint with it. If the resulting set of factors satisfies the primary authentication requirements and requirements, the intermediate session token will be consumed and converted to a Member Session. If not, the same intermediate session token will be returned.

Parameters

password_reset_token
string
required
The password reset token to authenticate.
password
string
required
The password to authenticate, reset, or set for the first time. Any UTF8 character is allowed, e.g. spaces, emojis, non-English characters, etc.

Response

email_address
string
The email address that was authenticated.
discovered_organizations
object[]
An array of discovered Organizations that the Member can authenticate into.
intermediate_session_token
string
The intermediate session token that can be exchanged for a full session.