NodeJS Forbidden:/API/v1/token/logout/“POST /API/v1/token/logout/ HTTP/1.1”403 58

wgeznvg7  于 12个月前  发布在  Node.js
关注(0)|答案(1)|浏览(110)

我在学习教程后遇到了这个问题,我无法在我的“MyAccountView.vue”页面中识别错误。我尝试更改为re_path,但没有成功。

Forbidden: /api/v1/token/logout/
[16/Oct/2023 19:01:35] "POST /api/v1/token/logout/ HTTP/1.1" 403 58

产品编号:

酒店URLS.PY

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/', include('djoser.urls')),
    path('api/v1/', include('djoser.urls.authtoken'))
]

酒店SETTING.PY

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSESS':(
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSESS':(
        'rest_framework.permissions.IsAuthenticated',
    )
}

错误提示

Getting this error in browser's console

MyAccountView.vue

如果它的作品,我应该转发**"/"我的网站主页**。

methods: {
        logout() {
            axios
                .post("/api/v1/token/logout/")
                .then(response => {
                    axios.defaults.headers.common["Authorization"] = ""

                    localStorage.removeItem("token")

                    this.$store.commit('removeToken')

                    this.$router.push('/')
                })
                .catch(error => {
                    if (error.response) {
                        console.log(JSON.stringify(error.response.data))
                    } else if (error.message) {
                        console.log(JSON.stringify(error.message))
                    } else {
                        console.log(JSON.stringify(error))
                    }
                })
        }
    }
9avjhtql

9avjhtql1#

您正在使用djoser
您需要在Post请求中调用注销端点时传递令牌
范例:

.post('api/v1/token/logout/', token,
   {
     headers: {
       Authorization: `Token ${token}`  --> Add your token here.
     }
   })

相关问题