Hot answers tagged

3

Just found the solution: npm install qs and import qs from 'qs' ... const actions = { auth({ commit }, { email, password }) { axios.post('url', qs.stringify({ your token data here })).then((res) => { console.log(res.data) }).catch((err) => { console.log(err) }) } }


2

They don't need to clash per se, but it depends on the way you build your project structure. I'm front-end focussed, so my setup is like: projectfolder src public public (you could also call this 'craft' or 'dist' or another name to indicate this is the final product) This is where Craft is installed with the craft installer. So nothing ...


2

RAND() is the correct way to do this. (At least, it works in 3.5). One catch is that GraphQL queries are cached by default, so your results will always be returned in the same random order until your cache is invalidated. If you're using Nuxt with a static target, your entries will be displayed in the same order until the cache is expired and your app is ...


2

with a get request from /index.php?p=admin/actions/users/session-info&dontExtendSession=1 I can get my CSRF Code + the User ID. Great.


1

It sounds to me like you're running into a collision with Vue's template delimiters vs Twig's, which by default are the same as each other ({{ ... }}). The solution is to change Vue's delimiters to something else when you initialise, like this: const vm = new Vue({ el: '#app', delimiters: ['${', '}'], ... ... }); You'd then need to use ${ ......


1

UPD 2: Spending more hours gave me the solution: It seems like Ajax generates a new sessionId with each call, so it's impossible to preserve cart along with session Id in that case. As workaround I was trying to pass session id cookie manually, but it was rejected by Axios. What I have found is that you can actually call action=commerce/cart/get-cart&...


1

UPD: after some hours of research I found the solution in this topic: CORS preflight check failing for AJAX login form on different domain Also I had to pass the orderNumber parameter with the value of cart number in payload. However I have a different issue now. First I call ?action=commerce/cart/load-cart&note=from+ajax&number={number} to load my ...


1

And just like that I stumble over this wonderful blog post https://digitalevangelist.net/blog/vuejs-craft-cms-single-page-app-logging-in-to-craft


1

You would not use the headless API to submit content in into Craft, as neither the GraphQL or Element APIs support writing. The frontend entry form functionality is fairly well documented. You would just need your frontend to build out a post request including the correct action, CSRF token, and whatever fields are needed. The action endpoint will ...


1

The way Retour works, it doesn't do anything until Craft throws a 404 error. Some other plugins do this as well. Your route is such that anything Craft can't find goes to your SPA; that means Craft never throws a 404, so these tools will not do anything. What I'd suggest doing is have this redirect happen via your web server.


1

I ended up making a 404 template (which in atuality is the SPA index file) This causes the Craft redirects to take effect, and have the SPA as a fallback route. This means in Production i don't need any such route. For development purposes i do, so i made a conditional route file (to avoid the debug 404 of Craft): if(getenv('ENVIRONMENT') === 'dev') { ...


1

Not sure if it's a good call or not but you could have an endpoint that just has the {{ craft.app.request.csrfToken }} outputting on it. Poll(GET) that using ajax (axios or whatever you're using in your Vue app) and update your Vue model's csrf value with the response body? Same for the honeypot value I guess although I'm not that familiar with freeform I ...


1

You can use the asArray function to return arrays instead of elements {% set sections = craft .categories .group('teamCategory') .select(['title','elements.id','groupId']) .asArray() .all() %}


Only top voted, non community-wiki answers of a minimum length are eligible