Consumer Authentication

/

Frontend SDKs

/

Headless

/

Passwords

/

Create

Create

The Create method wraps the Create Password API endpoint. If a user with this email already exists in the project, this API will return an error. Existing passwordless users who wish to create a password need to go through the reset password flow.

This endpoint will return an error if the password provided does not meet our strength requirements, which you can check beforehand with the Strength Check Password API endpoint.

If this method succeeds, the user will be logged in, granted an active session, and the session cookies will be minted and stored in the browser.


Method parameters


email*string

password*string

session_duration_minutes*int
import { useCallback } from 'react';
import { useStytch } from '@stytch/react';

export const Login = () => {
  const stytch = useStytch();

  const createPassword = useCallback(() => {
    stytch.passwords.create({
      email: '${exampleEmail}',
      password: 'xY5jMLT8V1XYhRp+',
      session_duration_minutes: 60,
    });
  }, [stytch]);

  return <button onClick={createPassword}>Create Password</button>;
};

RESPONSE

200
{
    "status_code": 200,
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "user_id": "user-test-16d9ba61-97a1-4ba4-9720-b03761dc50c6",
    "email_id": "email-test-81bf03a8-86e1-4d95-bd44-bb3495224953"
  }