real estate API now gets citizen_upn from the jwt token

This commit is contained in:
Muhammad Azeez 2021-01-18 23:58:45 +03:00
parent 404e67df29
commit 38339dbeb1
3 changed files with 8 additions and 7 deletions

View File

@ -8,7 +8,10 @@ const pool = new Pool({
});
const getAllRealEstate = (request, response) => {
pool.query("SELECT * FROM real_estate ORDER BY id DESC", (error, results) => {
// The express-jwt middleware decodes the jwt token and store all claims on request.user
// https://github.com/auth0/express-jwt/issues/153#issuecomment-269498310
citizen_upn = request.user.sub;
pool.query(`SELECT * FROM real_estate WHERE citizen_upn = '${citizen_upn}' ORDER BY id DESC`, (error, results) => {
if (error) {
throw error;
}
@ -16,10 +19,10 @@ const getAllRealEstate = (request, response) => {
});
};
// We don't need the citizen_upn here? ** Temporary **
const insertRealEstate = (request, response) => {
const { address, area, citizen_upn } = request.body;
const { address, area } = request.body;
citizen_upn = request.user.sub;
console.log(citizen_upn)
pool.query(
"INSERT INTO real_estate (address, area, citizen_upn) VALUES ($1, $2, $3)",
[address, area, citizen_upn],

View File

@ -21,7 +21,7 @@ const VehicleRegisterForm = () => {
async function registerVehicle() {
await apiService.registerVehicle(
{ address, area, citizen_upn: user.profile.sub },
{ address, area },
user.access_token
);
history.push("/");

View File

@ -11,7 +11,6 @@ const Table = ({ vehicleData }) => {
<tr>
<ColumnName text={"Address"} />
<ColumnName text={"Area"} />
<ColumnName text={"Citizen UPN"} />
<th scope="col" className="relative px-6 py-3">
<span className="sr-only">Actions</span>
</th>
@ -22,7 +21,6 @@ const Table = ({ vehicleData }) => {
<tr key={vehicle.id} className="bg-gray-50">
<TableData text={vehicle.address} />
<TableData text={vehicle.area} />
<TableData text={vehicle.citizen_upn} />
<TableData Component={EditBtns} />
</tr>
))}