Facebook Provider error when no `cpTrigger` is defined (headless)
Description
The Facebook provider throws Undefined array key "host" when the cpTrigger is not set (when Craft is in headless mode).
Caused by this line in SocialPosterHelper.php:25
$redirectUri = str_replace(Craft::$app->getConfig()->getGeneral()->cpTrigger . '/', '', $redirectUri);
https://github.com/verbb/social-poster/blob/craft-3/src/helpers/SocialPosterHelper.php#L25
So this helper function is really only there to generate the redirect URI for OAuth. I'm not sure why the headless config setting has any issue here, as you still need to access the control panel for Craft.
When are you seeing this error exactly?
@engram-design It's when we try to access the providers index
Strange, I've got headlessMode => true enabled on my install. Are you able to send through the full error with devMode on?
And just to verify headlessMode was working, my front-end is offline (in a traditional Twig setup).
Are you setting baseCpUrl in your config?
The issue seems to be caused by cpTrigger being set to null (since we're running craft headless on a sub-domain). This then causes the str_replace to see only the / and goes ahead and removes all slashes. This means the redirectUri goes from something like https://github.com/verbb/social-poster/issues/36 to https:github.comverbbsocial-posterissues36
Right, gotcha. Setting cpTrigger => null will do this, and not something I've ever seen before. I'll get a setup organised to test that (I get all sorts of errors trying to access the CP with this set to null)
We normally stick this at the top of our web/index.php if it helps!
if (
$_SERVER['REQUEST_URI'] !== '/graph' &&
strpos($_SERVER['REQUEST_URI'], '.xml') === false
) {
define('CRAFT_CP', true);
}