# Token Refreshing

## `Token Refreshing`

The `/auth/refresh` endpoint is a POST request that is used to refresh a user's session. This is particularly useful when the user's session has expired and needs to be renewed.

The Moon SDK will automatically refresh the user's session when it expires. This means that you don't have to manually refresh the session in most cases. However, this endpoint is still useful in scenarios where you need to manually control the session refresh.

### Request

The request should include a `refresh_token` in the body. This token is used to authenticate the user and generate a new session.

```json
{
  "refresh_token": "your_refresh_token_here"
}
```

### Response

The response will return the new session data if the request is successful. If there is an error, it will return a 500 status code along with the error message.

### Code Example

Here is an example of how to use this endpoint:

```typescript
import axios from 'axios';

const refreshToken = 'your_refresh_token_here';

axios.post('https://beta.usemoon.ai/auth/refresh', { refresh_token: refreshToken })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });
```


---

# 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://docs.usemoon.ai/authentication-750f0518f1d64f82a7ef38dd5cbc4b64/token-refreshing.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.
