doublesecretagency / craft-digitaldownload

Digital Download plugin for Craft CMS
Other
4 stars 4 forks source link

Non-object error in user logged in check #8

Closed extensibleseth closed 2 years ago

extensibleseth commented 4 years ago

When authenticating by loggedinedness the user object wasn't set and threw an error when trying to access it's id. I moved the redirect bit inside that check to work around it.

In Downloads.php:383

        // User must be logged in
        if ('*' === $requirement) {
            // If they are not logged in
            if (!$this->_user) {
                // Redirect to the login page specified by loginPath
                Craft::$app->getUser()->loginRequired();
                Craft::$app->end();
            }
            return (bool) $this->_user->id;
        }
corneliusio commented 2 years ago

This is also causing issues for us as this sends unauthenticated users to our 500 page and our client would like to handle unauthenticated users more elegantly for downloads. Any chance this could get resolved soon? Am more than happy to submit a PR as I believe the only thing that needs an adjustment would be the check at Downloads.php:392

        if ('*' === $requirement) {
-            return (bool) $this->_user->id;
+            return isset($this->_user->id);
        }
lindseydiloreto commented 2 years ago

This is now fixed in v2.2.1. Thanks! 🍺