diff --git a/extend.php b/extend.php index 26831b3..9df1104 100644 --- a/extend.php +++ b/extend.php @@ -15,6 +15,7 @@ use Flarum\Api\Serializer\ForumSerializer; use Flarum\Extend; use Flarum\Frontend\Document; +use Flarum\Settings\Event\Saving; use Flarum\User\Event\LoggedOut; use FoF\Extend\Events\OAuthLoginSuccessful; @@ -50,8 +51,7 @@ ->register(OAuthServiceProvider::class), (new Extend\ApiSerializer(ForumSerializer::class)) - ->attributes(function (ForumSerializer $serializer) { - $attributes = []; + ->attributes(function (ForumSerializer $serializer, $model, array $attributes): array { if ($serializer->getActor()->isGuest()) { $attributes['fof-oauth'] = resolve('fof-oauth.providers.forum'); } @@ -72,7 +72,8 @@ (new Extend\Event()) ->listen(OAuthLoginSuccessful::class, Listeners\UpdateEmailFromProvider::class) - ->listen(LoggedOut::class, Listeners\HandleLogout::class), + ->listen(LoggedOut::class, Listeners\HandleLogout::class) + ->listen(Saving::class, Listeners\ClearOAuthCache::class), (new Extend\ApiSerializer(CurrentUserSerializer::class)) ->attributes(Api\CurrentUserAttributes::class), diff --git a/src/Listeners/ClearOAuthCache.php b/src/Listeners/ClearOAuthCache.php new file mode 100644 index 0000000..4acc1d8 --- /dev/null +++ b/src/Listeners/ClearOAuthCache.php @@ -0,0 +1,28 @@ +cache = $cache; + } + + public function handle(Saving $event) + { + foreach (array_keys($event->settings) as $key) { + if (Str::startsWith($key, 'fof-oauth')) { + $this->cache->forget('fof-oauth.providers.forum'); + $this->cache->forget('fof-oauth.providers.admin'); + break; // Exit the loop once the cache is cleared + } + } + } +}