How can i get adonis-session-value with adonuxt-template
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 ~
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) {
});
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.
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
...
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
thank you it works !!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.