Able Pro
Vue Laravel
Vue Laravel
  • Documentation
  • Installation
  • Directory Structure
  • ⛱️Theme UI
    • 🎛️Icons
    • 👓Change Logo
    • 🆎Change Typography
    • 🔮Theme Colors
    • ⚙️Theme Settings
    • ⬅️RTL
  • 👩‍💻Development
    • Database Connection
    • Sanctum Integration
    • Sanctum Authentication
    • Frontend API
    • State Management
    • Axios API Calls
    • Routing
  • Perfect Scrollbar
  • Layouts
  • Create a new page
  • Remove Auth
  • Dependencies
  • Roadmap
  • Changelog
Powered by GitBook
On this page
  1. Development

Frontend API

We have to create Laravel APIs before testing the frontend API Call.

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

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
  }
}
PreviousSanctum AuthenticationNextState Management

Last updated 1 year ago

👩‍💻