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 ...
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,
...
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 ...
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({ ...
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.
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....
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), ...
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 ...
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 ...
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 ...
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 ...
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 ...
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::...
1
vote
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 ...
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.
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
headless × 22craft3 × 5
live-preview × 4
graphql × 4
localization × 2
plugin-elementapi × 2
login × 2
csrf × 2
vue × 2
plugin-development × 1
plugin-craftcommerce × 1
plugins × 1
users × 1
config × 1
cache × 1
image-transforms × 1
ajax × 1
admin × 1
javascript × 1
routing × 1
plugin-craftcommerce3 × 1
language × 1
authentication × 1
configuration × 1
subdomain × 1