Skip to main content
4 votes
Accepted

CSRF in “Headless” Applications

A similar question was asked in the Craft Slack today, so I thought I'd transcribe the consensus: Internally, CSRF tokens come from a call to Craft::$app->getRequest()->getCsrfToken(). This ...
August Miller's user avatar
3 votes
Accepted

Headless CraftCMS as mobile app backend, requiring login

You could make the CSRF token available via an element API endpoint, then submit the form with that; 'api/csrf-token' => [ 'elementType' => GlobalSet::class, 'paginate' => false, ...
dmatthams's user avatar
  • 2,492
3 votes

Headless CraftCMS: How can I tell Craft to load live preview from a different (sub)domain?

Since Craft 3.3.1, you can create a custom alias that resolves to your frontend base URL, and add that alias to the relevant preview targets' "URL Format" setting. For example, assuming you put ...
Mats Mikkel Rummelhoff's user avatar
2 votes

Headless Live Preview with Gatsby

they updated the sourceNodes cycle since this config, you will need to update the schema first doing something like this: An example using the body hook if you need it: createSchemaCustomization({ ...
Anthony Ferreol's user avatar
2 votes
Accepted

getting active userid by GraphQL?

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.
Peter L's user avatar
  • 86
2 votes

How to loop through Craft CMS query in Angular

Got it working like this: <ng-template ngFor let-obj [ngForOf]="entry.imageHero"> <h1>{{ obj.heroTitle }}</h1> </ng-template> This also works: {{ entry....
Trish20's user avatar
  • 31
2 votes

How do you set up live preview for headless Craft CMS installs connected to Gatsby?

When you enter live preview in the cp, it's an iframe to the URL you've set up for that section, including a token=xxxxxxxx, you need to pass this along to your GraphQL (assuming that's what you use), ...
peirix's user avatar
  • 431
2 votes

WARNING: heuristic fragment matching going on! when querying matrix fields or any query with multiple fragment types with Graph QL using Nuxt Apollo

I struggled with this for ages, but after @mylesthe.dev (who responded to one of the posts i mention above) spoke to me directly to provide fantastic support and some examples, I figured it out. So ...
ToddPadwick's user avatar
2 votes

JS login form on different domain and handling the CSRF token

I don't have a good answer for this, but my response is too long to to put into a comment so here goes. I've been experiencing the same thing — I can successfully retrieve the CSRF token, but when I ...
Dalton Rooney's user avatar
2 votes

Is there a guide for using Craft Commerce headless?

After looking at the Commerce docs further, I see I can use the GraphQL API to get information from Commerce. That is, at least for products. Craft 3.5 will allow GraphQL mutations so perhaps that’ll ...
William's user avatar
  • 41
2 votes
Accepted

CraftCMS + GraphQL - orderBy Random?

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 ...
Dalton Rooney's user avatar
1 vote

Is there a way to determine an element by its path or full url instead of the uri?

You can always use the search function -> https://craftcms.com/docs/4.x/searching.html which works excellent, especially via GraphQl. If you need to query for full Urls I would probably strip it to ...
thomas's user avatar
  • 131
1 vote

CraftCMS headless / Nuxt - not getting live preview to work

The tokens need to be in the request headers or query string, not in the body of the request. We use a different request lib, but try something like this: const entry = await app.apolloProvider....
Josh Coady's user avatar
1 vote

GraphQL fields with applied typogrify - any suggestions?

So unfortunately, the short answer is that you can't. When you switch to using something else as the frontend for a Craft site (as opposed to Twig) you lose things like the Twig filter typogrify. ...
andrew.welch's user avatar
  • 11.6k
1 vote
Accepted

Language prefix in URL with correct entry URIs

You include the language prefix in each site's URL setting as per the documentation. It's fine that URIs of entries don't include the site URL, this way they stay language-independent. You wouldn't ...
MoritzLost's user avatar
  • 11.5k
1 vote

Persist session from frontend login form to craft dashboard on headless install

You can use defaultCookieDomain config setting to make all Craft cookies use your root domain: // config/general.php // mind the dot at the start 'defaultCookieDomain' => '.mydomain.com', This ...
MoritzLost's user avatar
  • 11.5k
1 vote
Accepted

Additional code to run when cache is busted(entry added/updated, etc)

Sounds like a custom plugin or module would work for you here, allowing you to hook into the entry after save event. use craft\elements\Entry; use craft\events\ModelEvent; use yii\base\Event; Event::...
Matt Banner's user avatar
1 vote

WARNING: heuristic fragment matching going on! when querying matrix fields or any query with multiple fragment types with Graph QL using Nuxt Apollo

For Apollo client 3.x users Apollo client now uses possibleTypes instead of IntrospectionFragmentMatcher You can manage schema.json as per other answer, but then use as such: const possibleTypes = {} ...
misteraidan's user avatar
1 vote

Headless mode/ElementAPI: how to set the frontend's baseUrl in the backend endpoint?

Apparently, the answers are the following: Redactor doesn't know how to output slugs/URIs instead of full URLs Possibly a solution comes up with craft in the future My API setup is suboptimal: In ...
Urs's user avatar
  • 639
1 vote

Image processing in headless mode

Check out the Imager Pre-transform plugin, or I can recommend a service like https://www.imgix.com where you can perform transforms using url parameters.
dmatthams's user avatar
  • 2,492
1 vote

Using Craft to render frontend pages in addition to using it headless

Absolutely! Craft works really well like this. You can use twig to render your website, then either element api or graph QL (built in to craft 3.3) to open up your data to other applications. I run ...
dmatthams's user avatar
  • 2,492

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