Skip to content

Commit 88c6f30

Browse files
committed
Store the JWT expiration time into ENV
1 parent a1fba19 commit 88c6f30

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

.env.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# API URL
22
APP_URL="http://localhost:8080"
33

4+
# JSON Web Token
45
JWT_KEY=""
6+
JWT_TOKEN_EXPIRATION="86400" # in seconds
57
JWT_ALGO_ENCRYPTION="HS512"
68

79
# Database details

src/Service/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class User
1717
{
1818
public const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
1919

20-
public function login(mixed $data)
20+
public function login(mixed $data): array
2121
{
2222
$userValidation = new UserValidation($data);
2323
if ($userValidation->isLoginSchemaValid()) {
@@ -32,7 +32,7 @@ public function login(mixed $data)
3232
[
3333
'iss' => $_ENV['APP_URL'],
3434
'iat' => $currentTime,
35-
'exp' => $currentTime + (60 * 60), // valid for an hour
35+
'exp' => $currentTime + $_ENV['JWT_TOKEN_EXPIRATION'],
3636
'data' => [
3737
'email' => $data->email,
3838
'name' => $userName

0 commit comments

Comments
 (0)