core icon indicating copy to clipboard operation
core copied to clipboard

How can i get adonis-session-value with adonuxt-template

Open dhlim-dev opened this issue 8 years ago • 6 comments

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 ~

dhlim-dev avatar Jan 26 '18 01:01 dhlim-dev

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) {
});

touskar avatar Jan 26 '18 02:01 touskar

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.

dhlim-dev avatar Jan 26 '18 03:01 dhlim-dev

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
...

dhlim-dev avatar Jan 26 '18 03:01 dhlim-dev

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

thetutlage avatar Jan 26 '18 05:01 thetutlage

thank you it works !!

dhlim-dev avatar Jan 26 '18 05:01 dhlim-dev

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.

lock[bot] avatar Mar 11 '20 08:03 lock[bot]