From d8fc3477287ee4f915eb8c11d25b5b7c808828b1 Mon Sep 17 00:00:00 2001 From: Wisdom Ebong Date: Mon, 19 Jul 2021 10:13:53 +0100 Subject: [PATCH] refactor: config storage driver for tokens --- src/TokenConfigStorage.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/TokenConfigStorage.php b/src/TokenConfigStorage.php index 2d22292..901c6d0 100644 --- a/src/TokenConfigStorage.php +++ b/src/TokenConfigStorage.php @@ -30,17 +30,17 @@ public function save($token) { $gmailConfig = $this->configRepo->get('gmail'); $dataProvider = $this->configRepo->get('data-provider'); - + $credentials = $dataProvider->asArray()['gmail']; $credentials['email'] = $token['email']; $credentials['authenticated'] = empty($token) ? false : true; - + $gmailConfig->setState([ "token_for_{$token['email']}" => $token, ]); $dataProvider->setState([ - 'gmail' => $credentials + 'gmail' => $credentials ]); $this->configRepo->update($gmailConfig); @@ -49,6 +49,19 @@ public function save($token) public function delete($email) { - $this->save(['email' => $email]); + $gmailConfig = $this->configRepo->get('gmail'); + $dataProvider = $this->configRepo->get('data-provider'); + $credentials = $dataProvider->asArray()['gmail']; + + $dataProvider->setState([ + 'gmail' => $credentials + [ 'email' => '', 'authenticated' => false ] + ]); + + $gmailConfig->setState([ + "token_for_{$email}" => '', + ]); + + $this->configRepo->update($gmailConfig); + $this->configRepo->update($dataProvider); } }