> For the complete documentation index, see [llms.txt](https://docs.17movement.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.17movement.net/phone/building-custom-apps/auth/defining-global-types.md).

# DEFINING GLOBAL TYPES

To ensure Type Safety throughout the application and allow the [**TypeScript**](https://www.typescriptlang.org/) compiler to recognize the new global authentication functions (such as `handleLogin` and `handleRegister`), we must extend the global type declarations.

### Implementation

Open the file `web/src/types.d.ts` and add the following type declarations starting from `handleLogin` down to `useSignOut`. These definitions inform **TypeScript** about the existence, arguments, and return types of these functions, preventing compilation errors in the views and hooks.

{% code overflow="wrap" lineNumbers="true" %}

```typescript
declare function handleLogin(
    username: string,
    password: string
): Promise<{ success: boolean; message: string; }>;

declare function handleRegister(
    username: string,
    password: string,
    accountData: unknown,
): Promise<{ success: boolean; message: string; }>;

declare function useCurrentUser(): { username: string; accountData: unknown } | null;

declare function useIsAuthenticated(): boolean;
declare function useSignOut(): void;
```

{% endcode %}

{% hint style="info" %}
***Note**: The existing utility declarations (e.g., `openGalleryPicker`, `startCall`, `useSettings`, etc.) already present in `types.d.ts` should remain untouched. You only need to append the new authentication declarations listed above.*
{% endhint %}

### Functions Reference

#### `handleLogin`

```typescript
const response = await handleLogin(
    'username', 
    'password'
);
console.log(response);
```

**Arguments**

<table><thead><tr><th width="120" align="center">Name</th><th width="100" align="center">Type</th><th width="100" align="center">Optional</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>username</code></td><td align="center">string</td><td align="center">❌</td><td>The username to attempt login with.</td></tr><tr><td align="center"><code>password</code></td><td align="center">string</td><td align="center">❌</td><td>The user's password.</td></tr></tbody></table>

**Returns**

<table><thead><tr><th width="120" align="center">Name</th><th width="95" align="center">Type</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>success</code></td><td align="center">boolean</td><td>The <code>success</code> boolean is <code>true</code> upon success.</td></tr><tr><td align="center"><code>message</code></td><td align="center">string</td><td>The <code>message</code> string provides an error description (if unsuccessful) or a confirmation message.</td></tr></tbody></table>

#### `handleRegister`

**Example**

```typescript
const response = await handleRegister(
    'newuser',
    'securepassword',
    {
        email: 'test@example.com',
        age: 30
    }
);
console.log(response);
```

**Arguments**

<table data-header-hidden><thead><tr><th width="120" align="center">Name</th><th width="100" align="center">Type</th><th width="100" align="center">Optional</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>username</code></td><td align="center">string</td><td align="center">❌</td><td>The username for the new registration.</td></tr><tr><td align="center"><code>password</code></td><td align="center">string</td><td align="center">❌</td><td>The new user's password.</td></tr><tr><td align="center"><code>accountData</code></td><td align="center">unknown</td><td align="center">✅</td><td>Optional additional account data to be saved (e.g., email, date of birth). Can be <code>null</code>.</td></tr></tbody></table>

**Returns**

<table><thead><tr><th width="120" align="center">Name</th><th width="95" align="center">Type</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>success</code></td><td align="center">boolean</td><td>The <code>success</code> boolean is <code>true</code> upon success.</td></tr><tr><td align="center"><code>message</code></td><td align="center">string</td><td>The <code>message</code> string provides an error description (if unsuccessful) or a confirmation message.</td></tr></tbody></table>

#### `useCurrentUser`

**Example**

```typescript
const user = useCurrentUser();
if (user) {
    console.log(`Logged in as: ${user.username}`);
}
```

**Returns**

<table><thead><tr><th width="120" align="center">Name</th><th width="100" align="center">Type</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>username</code></td><td align="center">string</td><td>Current login username</td></tr><tr><td align="center"><code>accountData</code></td><td align="center">unknown</td><td>Return data provided while registering</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.17movement.net/phone/building-custom-apps/auth/defining-global-types.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
