Skip to content

Commit

Permalink
Some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Erkelens committed Aug 12, 2017
1 parent 4ad11db commit 15bf576
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
23 changes: 12 additions & 11 deletions src/Mutations/RefreshTokenMutationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function args()
* @param mixed $context
* @param ResolveInfo $info
* @return Member|null
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \SilverStripe\ORM\ValidationException
* @throws \BadMethodCallException
* @throws \OutOfBoundsException
*/
Expand All @@ -53,20 +55,19 @@ public function resolve($object, array $args, $context, ResolveInfo $info)
}

$expired = false;
if ($member === null) {
// If we have a valid member, or there are no matches, there's no reason to go in here
if ($member === null && !empty($matches[1])) {
foreach ($result->getMessages() as $message) {
if (strpos($message['message'], 'Token is expired') === 0) {
if (strpos($message['message'], 'Token is expired') !== false) {
// If expired is true, the rest of the token is valid, so we can refresh
$expired = true;
if (!empty($matches[1])) {
// We need a member, even if the result is false
$parser = new Parser();
$parsedToken = $parser->parse((string)$matches[1]);
/** @var Member $member */
$member = Member::get()
->filter(['JWTUniqueID' => $parsedToken->getClaim('jti')])
->byID($parsedToken->getClaim('uid'));
}
// We need a member, even if the result is false
$parser = new Parser();
$parsedToken = $parser->parse((string)$matches[1]);
/** @var Member $member */
$member = Member::get()
->filter(['JWTUniqueID' => $parsedToken->getClaim('jti')])
->byID($parsedToken->getClaim('uid'));
}
}
} elseif ($member) {
Expand Down
12 changes: 7 additions & 5 deletions src/Types/MemberTokenTypeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public function attributes()

public function fields()
{
$string = Type::string();
$id = Type::id();
return [
'ID' => ['type' => Type::id()],
'FirstName' => ['type' => Type::string()],
'Surname' => ['type' => Type::string()],
'Email' => ['type' => Type::string()],
'Token' => ['type' => Type::string()]
'ID' => ['type' => $id],
'FirstName' => ['type' => $string],
'Surname' => ['type' => $string],
'Email' => ['type' => $string],
'Token' => ['type' => $string]
];
}
}

0 comments on commit 15bf576

Please sign in to comment.