From 681ab12f7660ba38f7fbb1ca399b3432ffbd0d84 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Wed, 10 Mar 2021 15:25:54 -0500 Subject: [PATCH] Instantiate jwt outside conditionals --- app/controllers/api/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 23273f6ba..6c9bd6192 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -735,12 +735,12 @@ App::post('/v1/functions/:functionId/executions') if (false === $execution) { throw new Exception('Failed saving execution to DB', 500); } - + + $jwt = ''; // initialize if (!empty($user->getId())) { // If userId exists, generate a JWT for function $tokens = $user->getAttribute('tokens', []); $session = new Document(); - $jwt = ''; foreach ($tokens as $token) { /** @var Appwrite\Database\Document $token */ if ($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too @@ -749,8 +749,8 @@ App::post('/v1/functions/:functionId/executions') } if(!$session->isEmpty()) { - $newjwt = new JWT(App::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway. - $jwt = $newjwt->encode([ + $jwtObj = new JWT(App::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway. + $jwt = $jwtObj->encode([ 'userId' => $user->getId(), 'sessionId' => $session->getId(), ]);