{"action":"created","issue":{"url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/1568","repository_url":"https://api.github.com/repos/firefly-iii/firefly-iii","labels_url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/1568/labels{/name}","comments_url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/1568/comments","events_url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/1568/events","html_url":"https://github.com/firefly-iii/firefly-iii/issues/1568","id":344017344,"node_id":"MDU6SXNzdWUzNDQwMTczNDQ=","number":1568,"title":"[Sandstorm] Firefly III creates more than one user instead of using the main user","user":{"login":"jemaph","id":35311811,"node_id":"MDQ6VXNlcjM1MzExODEx","avatar_url":"https://avatars2.githubusercontent.com/u/35311811?v=4","gravatar_id":"","url":"https://api.github.com/users/jemaph","html_url":"https://github.com/jemaph","followers_url":"https://api.github.com/users/jemaph/followers","following_url":"https://api.github.com/users/jemaph/following{/other_user}","gists_url":"https://api.github.com/users/jemaph/gists{/gist_id}","starred_url":"https://api.github.com/users/jemaph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jemaph/subscriptions","organizations_url":"https://api.github.com/users/jemaph/orgs","repos_url":"https://api.github.com/users/jemaph/repos","events_url":"https://api.github.com/users/jemaph/events{/privacy}","received_events_url":"https://api.github.com/users/jemaph/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-24T12:34:35Z","updated_at":"2018-07-24T14:06:44Z","closed_at":null,"author_association":"NONE","body":"**Bug description**\r\nI am running Firefly III version 4.7.5.1 on Sandstorm\r\n\r\nI've noticed since the lastest update that users with whom they've shared a Firefly III grain can't access the account's data, and are shown the interface as if nothing was present.\r\n\r\n**Steps to reproduce**\r\nCreate a Firefly III grain on Sandstorm, share it to another user, the new user won't be able access the data created by the first and his profile will show an ID of 2 or more.\r\nI managed to reproduce the bug on Sandstorm Oasis in demo mode\r\n\r\n**Extra Info**\r\nI've found the root cause as being an old version of `app/Http/Middleware/Sandstorm.php` being packaged inside the spk.\r\nOur installed version comes from here\r\nhttps://apps.sandstorm.io/app/uws252ya9mep4t77tevn85333xzsgrpgth8q4y1rhknn1hammw70\r\nThe spk package being https://app-index.sandstorm.io/packages/ed958b9fed3330f1e48a2b0603e82950\r\nWhen I checked the contents of the file using `spk unpack` on the package that I've downloaded from there, I found out that it didn't handle multiple users gracefully.\r\n\r\nThis is a snippet taken from the file extracted\r\n```php\r\n    public function handle(Request $request, Closure $next, $guard = null)\r\n    {\r\n        // is in Sandstorm environment?\r\n        $sandstorm = 1 === (int)getenv('SANDSTORM');\r\n        app('view')->share('SANDSTORM', $sandstorm);\r\n        if (!$sandstorm) {\r\n            return $next($request);\r\n        }\r\n\r\n        // we're in sandstorm! is user a guest?\r\n        if (Auth::guard($guard)->guest()) {\r\n            /** @var UserRepositoryInterface $repository */\r\n            $repository = app(UserRepositoryInterface::class);\r\n            $userId     = (string)$request->header('X-Sandstorm-User-Id');\r\n            // catch anonymous:\r\n            $userId = $userId === '' ? 'anonymous' : $userId;\r\n            $email  = $userId . '@firefly';\r\n            $user   = $repository->findByEmail($email) ?? $this->createUser($email);\r\n            Log::debug(sprintf('Sandstorm user email is \"%s\"', $email));\r\n\r\n            Auth::guard($guard)->login($user);\r\n            $repository->attachRole($user, 'owner');\r\n            app('view')->share('SANDSTORM_ANON', false);\r\n        }\r\n\r\n        return $next($request);\r\n    }\r\n```\r\nI tried updating the file but it didn't work without overriding the checks on $count as the database now contains more than one user (making the latest code throw an exception saying `Your Firefly III installation has more than one user, which is weird.`)\r\n"},"comment":{"url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/comments/407419136","html_url":"https://github.com/firefly-iii/firefly-iii/issues/1568#issuecomment-407419136","issue_url":"https://api.github.com/repos/firefly-iii/firefly-iii/issues/1568","id":407419136,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzQxOTEzNg==","user":{"login":"ocdtrekkie","id":4399499,"node_id":"MDQ6VXNlcjQzOTk0OTk=","avatar_url":"https://avatars0.githubusercontent.com/u/4399499?v=4","gravatar_id":"","url":"https://api.github.com/users/ocdtrekkie","html_url":"https://github.com/ocdtrekkie","followers_url":"https://api.github.com/users/ocdtrekkie/followers","following_url":"https://api.github.com/users/ocdtrekkie/following{/other_user}","gists_url":"https://api.github.com/users/ocdtrekkie/gists{/gist_id}","starred_url":"https://api.github.com/users/ocdtrekkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocdtrekkie/subscriptions","organizations_url":"https://api.github.com/users/ocdtrekkie/orgs","repos_url":"https://api.github.com/users/ocdtrekkie/repos","events_url":"https://api.github.com/users/ocdtrekkie/events{/privacy}","received_events_url":"https://api.github.com/users/ocdtrekkie/received_events","type":"User","site_admin":false},"created_at":"2018-07-24T14:06:44Z","updated_at":"2018-07-24T14:06:44Z","author_association":"NONE","body":"I would definitely say the expected behavior of sharing a Firefly III grain with someone is that that person would be able to see their Firefly III data. Presumably if someone wanted their own Firefly III data, they'd make their own Firefly III grain."}}
{"actor":{"display_login":"ocdtrekkie"}}