Skip to content

Commit

Permalink
refactor: config storage driver for tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisdom Ebong committed Jul 19, 2021
1 parent 7cdc30b commit d8fc347
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/TokenConfigStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit d8fc347

Please sign in to comment.