The token.php configuration file stores all the settings for your JWT token, including the expiration datetime and issuer.
3
The Generate.php file is used to create a token when the "Token Generation" endpoint is called with a valid username and password.
4
The `Validatetoken.php` file is used to validate the token for each request.
5
6
open "Validatetoken.php" file
7
Search for $decodedJWTData
(This variable will be globally accessible to all API endpoints.)
8
If the token is valid $decodedJWTData variable will have data.
9
API project folder
10
Let's attempt to modify the business endpoint to retrieve all businesses based on the logged-in user.
11
Open the business folder
12
The business folder contains all the generated endpoints.
13
Lets open read.php which return GET ALL business.
14
read.php file to get all business.
15
Create the object of Business class.
16
Assign different properties: Retrieve the user ID of the logged-in user from `$decodedJWTData` and set it to the business object before making the database call.
17
Database function call.
18
If you want to know what data is stored in your token you can use var_dump to print.
19
Here, I am assigning the owner ID to the logged-in user ID.
20
Let's examine the changes needed to read the database call.
21
Open "objects" folder for database functions.
22
23
Open business.php file
24
25
Search for read() function
26
In the SQL query to select all.
Add a `WHERE` clause to filter by `owner_id`.
27
Add the binding parameter
28
Save the file
29
In the same file business.php search for total_record_count function
30
Add a `WHERE` clause to filter by `owner_id`.
31
Binding parameter
32
Save the file.
33
In Postman I have generated token for user with id 1.
34
Open Business GET ALL request.
35
Click Send
36
We got total of 1 record.
37
With owner id as provided by token. (user id =1)
38
To verify the data, you can execute a similar query directly on the database.