发表文章

[Javascript] 如何使用 adonuxt-模板来获取多尼斯会话值 "How can i get adonis-session-value with adonuxt-template"[adonis-framework]

gongzza 17天前 5

我希望使用CSRF 保护, 但 EBADCSRFTOKEN: Invalid CSRF token adonis-session-value 在请求 POST 方法时, 我得到了因为没有。

我从这个蓝图开始
nuxt-社区/adonuxt-模板

并打开索引页。

我得到了 adonis-sessionXSRF-TOKEN cookie. 但我没有得到adonis-session-value

我检查过 session.drive 是 cookie。

帮我一下 ~

原文:

i want to use CSRF protection but i got EBADCSRFTOKEN: Invalid CSRF token because i have no adonis-session-value when i request POST method.

i started with this blueprint
nuxt-community/adonuxt-template

and open the index page.

i got the adonis-session and XSRF-TOKEN cookie. but i didn't get adonis-session-value

i checked session.drive is cookie.

help me please ~

相关推荐
最新评论 (5)
touskar 17天前
1

如果是 ajax 请求, 请确保将该令牌发送回服务器, 如下所说:

$.ajaxSetup({
    headers: {
        'X-XSRF-TOKEN': '{{ csrfToken }}'
    }
});

或在执行请求时:

$.post('/some_route', {
    _csrf:"{{ csrfToken }}",
    name: '...',
    email: '....'
}, function(data) {
});
原文:

If it's an ajax request, make sure you send the token back to server like that:

$.ajaxSetup({
    headers: {
        'X-XSRF-TOKEN': '{{ csrfToken }}'
    }
});

Or while doing request:

$.post('/some_route', {
    _csrf:"{{ csrfToken }}",
    name: '...',
    email: '....'
}, function(data) {
});
gongzza 17天前
2

我使用it。因此, X-XSRF-TOKEN 已在 http 标头中。

我想 Shild 基于会话. 但我没有 adonis-session-value , 所以 Shild 无法获取 csrfSecret 所以我得到了 Invalid CSRF token 响应。

原文:

i use axios. so X-XSRF-TOKEN is already in the http header.

i guess Shild based on session. but i have no adonis-session-value so Shild couldn't get csrfSecret so i got Invalid CSRF token response.

gongzza 17天前
3

调试日志:

2018-01-26T03:40:09.598Z adonis:framework new request on / url
...
2018-01-26T03:40:09.912Z adonis:session using cookie driver
2018-01-26T03:40:09.940Z adonis:session touching session to remain active
2018-01-26T03:40:09.940Z adonis:session using session id as de905de1-7211-46ae-bfc4-4e36037ee780
2018-01-26T03:40:09.941Z adonis:session session store initiated
...
2018-01-26T03:40:16.702Z adonis:framework new request on /api/echo url
...
2018-01-26T03:40:16.756Z adonis:session using cookie driver
for user
2018-01-26T03:40:16.757Z adonis:session touching session to remain active
2018-01-26T03:40:16.757Z adonis:session using session id as de905de1-7211-46ae-bfc4-4e36037ee780
2018-01-26T03:40:16.757Z adonis:session fetch driver session value as undefined
2018-01-26T03:40:16.757Z adonis:session session store initiated
2018-01-26T03:40:16.758Z adonis:fold resolving Adonis/Middleware/Shield namespace as a binding
2018-01-26T03:40:16.758Z adonis:fold resolving Adonis/Src/Config namespace as a binding
2018-01-26T03:40:16.760Z adonis:framework received error on /api/echo url
...
原文:

debug logs:

2018-01-26T03:40:09.598Z adonis:framework new request on / url
...
2018-01-26T03:40:09.912Z adonis:session using cookie driver
2018-01-26T03:40:09.940Z adonis:session touching session to remain active
2018-01-26T03:40:09.940Z adonis:session using session id as de905de1-7211-46ae-bfc4-4e36037ee780
2018-01-26T03:40:09.941Z adonis:session session store initiated
...
2018-01-26T03:40:16.702Z adonis:framework new request on /api/echo url
...
2018-01-26T03:40:16.756Z adonis:session using cookie driver
2018-01-26T03:40:16.757Z adonis:session existing session found for user
2018-01-26T03:40:16.757Z adonis:session touching session to remain active
2018-01-26T03:40:16.757Z adonis:session using session id as de905de1-7211-46ae-bfc4-4e36037ee780
2018-01-26T03:40:16.757Z adonis:session fetch driver session value as undefined
2018-01-26T03:40:16.757Z adonis:session session store initiated
2018-01-26T03:40:16.758Z adonis:fold resolving Adonis/Middleware/Shield namespace as a binding
2018-01-26T03:40:16.758Z adonis:fold resolving Adonis/Src/Config namespace as a binding
2018-01-26T03:40:16.760Z adonis:framework received error on /api/echo url
...
thetutlage 17天前
4

有一些问题与 Nuxt 模板, 我已经提交了公关为相同。现在我建议用我的叉子。

https://github.com/thetutlage/adonuxt-template

原文:

There are some issues with the Nuxt template, I have submitted a PR for same. For now I recommend using my fork.

https://github.com/thetutlage/adonuxt-template

gongzza 17天前
5

谢谢!

原文:

thank you it works !!

返回
发表文章
gongzza
文章数
1
评论数
3
注册排名
93361