0

I currently have a multi-site Craft 3 install with this in the general.php config file (amongst other settings)

return [
   '*' => [
       'defaultTokenDuration' => 259200, //72 hours
    ]
]

Which works fine for all sites allowing logged in users to remain logged in for 72 hours. I'm adding a new site where we need the duration to be 30 minutes.

I tried this:

return [
   '*' => [
        'defaultTokenDuration' => [
            '*' => 259200, //72 hours
            'otherSite' => 1800 //30 minutes
        ]
    ]
]

where 'otherSite' is the handle of the new site. Craft is throwing this error:

yii\base\InvalidConfigException: Unable to convert to seconds. in /Users/chad/Repos/gcx-craft/vendor/craftcms/cms/src/helpers/ConfigHelper.php:49

I also tried replacing the * with the handle of the primary site and saw the same error, so I assume listing all sites with a value in that array is useless. Is there any way to specify different values for different sites for this setting?

1 Answer 1

0

This is completely inaccurate, please disregard! I’ll work with Chad to come up with something useful, or delete it outright.


Multi-environment configuration (3.x) uses site handles at the top level of the returned array.

Currently, Craft interprets this as having the following defaultTokenDuration for all sites…

[
  '*' => 259200,
  'otherSite' => 1800,
]

…which isn't a valid "duration" format! 😉

Instead, your config file should look something like this:

return [
   '*' => [
        'defaultTokenDuration' => 259200,
    ],
    'otherSite' => [
        'defaultTokenDuration' => 1800,
    ],
];

💡 Keep in mind: These tokens aren’t always generated in circumstances where the current "site" is known or defined—for example, an administrator sending a password reset email to a user, or a live preview request.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.