# Frontend API

We have implemented login method in our `AuthLogin.vue` component file. You can find this file here: `resources/ts/views/authentication/AuthLogin.vue`

```typescript
async function login() {
  try {
    const res = await $api('/auth/login', {
      method: 'POST',
      body: {
        email: credentials.value.email,
        password: credentials.value.password,
      },
    })

    const { accessToken, userData, userAbilityRules } = res

    useCookie('userAbilityRules').value = userAbilityRules
    ability.update(userAbilityRules)

    useCookie('userData').value = userData
    useCookie('accessToken').value = accessToken

    // Redirect to `to` query if exists, otherwise redirect to index route
    await router.replace(route.query.to ? String(route.query.to) : '/dashboards/default')
  }
  catch (error) {
  // Handle errors
    console.error(error)
    errors.value.apiError = 'Invalid email or password' // Set error message for invalid credentials
  }
}
```


---

# 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://phoenixcoded.gitbook.io/able-pro/vue-laravel/development/frontend-api.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.
