> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create User

> Learn how to create new users in social.plus SDK through the login method

social.plus SDK creates new users through the `login` method. A single call to `login` creates the account if the `userId` does not exist, or authenticates the user if it does.

<Info>
  The `login` method serves dual purposes: it creates new users when they don't exist and authenticates existing users when they do.
</Info>

## How user creation works

When you call the `login` method:

1. **Existing user**: If a user exists with the specified `userId`, the SDK logs them in and optionally updates their `displayName`.
2. **New user**: If no user exists with the `userId`, the SDK creates a new account and logs them in automatically.

## Parameters

| Parameter        | Required           | Platforms                         | Description                                               |
| ---------------- | ------------------ | --------------------------------- | --------------------------------------------------------- |
| `userId`         | Yes                | TypeScript, iOS, Android, Flutter | Unique user identifier. Maximum length: 50 characters.    |
| `displayName`    | No                 | TypeScript, iOS, Android, Flutter | User-facing display name. Maximum length: 100 characters. |
| `authToken`      | No                 | TypeScript, iOS, Android, Flutter | Secure token used when your app enables secure mode.      |
| `sessionHandler` | Platform-dependent | TypeScript, iOS, Android, Flutter | Handles access-token renewal for authenticated sessions.  |

## Log in or create a user

Call the platform login method with a `userId`; include `displayName`, `authToken`, and session renewal handling when your integration needs them.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from '@amityco/ts-sdk';

  const sessionHandler: Amity.SessionHandler = {
    sessionWillRenewAccessToken(renewal) {
      renewal.renew();
    },
  };

  async function loginUser(userId: string, displayName?: string, authToken?: string) {
    Client.createClient('your-api-key', 'sg');

    await Client.login(
      {
        userId,
        displayName,
        authToken,
      },
      sessionHandler,
    );
  }

  await loginUser('user_123', 'Bob Newton');
  ```

  ```swift iOS theme={null}
  Task { @MainActor in
      do {
          try await client.login(
              userId: "<user-id>",
              displayName: "<(optional)-display-name>",
              authToken: "<(optional)-auth-token>",
              sessionHandler: sessionHandler
          )
          print("login success")
      } catch {
          print("login failed \(error)")
      }
  }
  ```

  ```kotlin Android theme={null}
  fun authenticate() {
      AmityCoreClient.login(userId = "userId 1", sessionHandler = null)
          .displayName(displayName = "John Doe") // optional
          .authToken(authToken = "token") // optional
          .build()
          .submit()
          .doOnComplete {
              //success
          }
          .subscribe()
  }
  ```

  ```dart Flutter theme={null}
  void login() async {
    await AmityCoreClient.login('userId', sessionHandler: (AccessTokenRenewal renewal) {
      renewal.renew();
    })
        .displayName('userDisplayName')
        .authToken('token') // optional
        .submit();
  }
  ```
</CodeGroup>

## Related topics

<CardGroup cols={2}>
  <Card title="Get User Information" href="./get-user-information" icon="user">
    Learn how to retrieve user data and profiles.
  </Card>

  <Card title="Update User Information" href="./update-user-information" icon="user-pen">
    Discover how to modify user profiles and settings.
  </Card>
</CardGroup>
