# signup

## Prerequisites

This tutorial requires you to be connected to the following. (For more information on connecting a server, see Overview.)

### Dependent Libraries

Only need reference two Javascript Libraries in HTML:

```markup
<script src="https://TML.ink/X.tml"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
```

The first line reference the client function library. This's a dynamic library includes many dynamic components and CDN resources, so don't save to local. The second line is using third-party socket library from CDN.

### Create a client instance

```java
tim = TML('wss://x.TML.ink'); //Create a client instance
```

If you connect multiple servers at the same time, you can create multiple client instances.

Connect a server, Load authentication module, Provide offline login codes and method, logout codes and method, multi-server login, automatic login, user cache and other functions of authentication. If you don't need these features, you should not execute this line of code.

### Sign Up a new user

```javascript
tim.X('user').New({
   email: "contact@TML.ink",
   password: "123"
     });
```

### Monitor user registration

```javascript
tim.X('user').on('add', function(msg){
   console.log(msg);
      });
```

Listen for real-time messages registered by users. This will be a mass message to update other users' interfaces without refreshing.

## Catch Sign Up's exception

Use try...catch statement marks a block of statements to try, and specifies a response, should an exception be thrown.

### Asynchronous catch

```javascript
tim.X('user').New({
   email: "contact@TML.ink",
   password: "123"
  }).then(function(data) {
    console.log(data);
  })
  .catch(function(err) {
    console.log(err);
  });
```

### Synchronous catch

```javascript
try {
  await tim.X('user').New({
     email: "contact@TML.ink",
     password: "123"
    });
} catch (err) {
  console.log(err);
};
```

## Complete codes of Sign Up

[import](https://github.com/NeoTim/Doc.tml.ink/tree/06db9df709caa4d33a18680add1c2990361c7b48/src/book/examples/signup_code.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.tml.ink/app-development/examples/signup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
