簡體   English   中英

我如何在我的 nuxt vps 上使用 laravel csrf 令牌

[英]how can i use laravel csrf token on my nuxt vps

我開始使用LaravelNuxt Js創建一個新應用程序 我有兩台VPS 服務器:

  1. 第一個包含我的Nuxt JS(前端)
  2. 第二個是基於Laravel的端點(后端)

我創建了很多頁面,我將數據正確插入到我的數據庫中。 現在我嘗試創建一個新函數來更新用戶數據,但是在提交表單后出現錯誤,因為我使用相同的 axios 代碼插入。

現在我在沒有令牌的情況下工作,我知道它的不安全方式。 我想知道如何在Nuxt JS前端Laravel后端之間通信令牌。 我有兩台服務器。

我得到的錯誤是:

CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException

這是我的 Axios 代碼:

edit (customerId, submit = false) {
  this.editMode = true
  this.customerId = customerId
  if (submit === 1) {
    const formData = $('#add-customer').serialize()
    this.$axios.$post('/customer/update', formData).then((response) => {
      this.refresh = true
    })
  } else {
    this.$axios.$get('/customer/edit?customer=' + customerId).then((response) => {
      this.formFields = response.data[0]
    })
  }
}

當我將這一行從 post 更改為 get 時,它工作正常

this.$axios.$post('/customer/update', formData)

我建議使用單個 Redis 服務器進行會話管理,這樣您就有一個集中的位置。 或使用數據庫,有關更多詳細信息,請查看 laravel 文檔

https://laravel.com/docs/6.x/session

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM