Skip to main content
import { useState } from 'react';
import { useSearchParams } from 'react-router';
import { useStytchB2BClient } from '@stytch/react/b2b';

export const DiscoveryResetPassword = () => {
  const stytch = useStytchB2BClient();
  const [searchParams] = useSearchParams();
  const [password, setPassword] = useState('');

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

  return (
    <form>
      <input
        type="password"
        value={password}
        onChange={(e) => setPassword(e.target.value)}
        placeholder="New Password"
      />
      <button onClick={resetPassword} type="submit">Reset Password</button>
    </form>
  );
};
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.