So right now, I am logged in as admin at example, dot com, and what we want to do this time around
is to implement the delete user functionality.
But before I do that, I'm going to open an incognito or private window and I want to go to localhost
four thousand and I will log in as Jack nimble.
So Jack and nimble dot com password, very secret and log in.
So in this window I'm logged in as Jack Nimble and it's a private window, as you can see up here.
So the session for this window is completely different from the session for this window where I'm logged
in as admin on that example dot com.
So I'm logged in twice, one in each window.
And let's go over to our code and let's find one user page go HTML.
And we already have a listener for the delete button.
Right here, but all we're doing is, of course, saying console dialog would delete user I.D., so
let's get rid of that and let's put in the appropriate check.
So we'll check to make sure that they confirm this, if result is confirmed, I believe is the syntax
and we'll try to delete the user.
So the logic for that from the front end will be pretty simple.
We'll create some request options.
So const request options equals and I'll just copy the ones from above to save some typing right here.
So will be post and headers will be exactly the same and there'll be nobody here.
OK, so I mean this over.
So we have our request options and we'll write the fetch statement, then we'll go put in the root and
the handler.
OK, so the statement will be we're going to fetch from or to appear like that slash admin, slash all
users, all the users, and then I'll call it delete and then I'll put the ID at the end of that and
we'll have to request options and we'll have a then and we'll convert our response into JSON as usual,
and then we'll run a function with our data and we'll check Finnair if data error and we'll do something
else, we'll do something else.
And something else is very simple.
Location equals slash.
It means all those users just take the user back to that page, all users page.
But if there's an error, then we'll just fire that swoll dot fire error with whatever error message
we got.
That data dot message.
OK, so that's the front end code and that all looks pretty accurate.
We might have a typo in there somewhere, but we'll find out before too long.
So let's go to our Roots Dash API and we'll add a root to delete a user.
So duplicate this route and change it to delete so and then the ID and we'll make this delete user and
we'll go create that function over in handler's dash API.
So it's a very simple function.
And to say some typing, I'll come up to this one, which is one user and I'll copy that.
And go to the bottom of this file and paste it in there and rename it to delete user when I did that,
because we need to get the ID, which we have right here, and then we're going to call or we're going
to get one return value from Abu DB dot delete user and handed the user ID.
And down here we need to write back a response so I can just copy all of this from the previous function
and paste it in here.
And you would think once I restart the application that this will be perfect.
Let's find out.
Let's see if we have any mistakes.
So I'll say mixed up, mixed start.
And remember, I'm logged in as two users.
So I'll go back to my Web browser right now, I'm not in the private window, so I'm met, I'm this
person and Minett example, dot com and you can verify that by clicking on it and there's no delete
button.
So I'll cancel of that.
Now we'll go over to Jack Nimble and I shall delete this user delete.
Are you sure you won't be able to undo this?
Delete the user.
Let's see if we got it right.
And it looks like we didn't, so I must have a typo in there somewhere expected nonwhite space character
after Jason data and learn one column, five of the Jason data.
So let's see what we got wrong.
Let's go see if there's an entry in our look.
Nothing there.
Let's see what we got back from our network.
So I'll just try this again.
Delete, delete.
And I have a four oh four.
So it looks like I have a mistake, which is.
The request is nothing, the response is 404 page not found and what did I actually request here?
Let's find out.
It's usually a JavaScript error with me.
And it looks like the initiator is a fair statement.
OK, that narrows it down.
So let's go back down to our first statement and see what we got wrong here.
And one user by French statement says, slash admin, slash all the users, fetch API, slash API,
slash admin.
All right, let's try that again.
So mixed up start.
I'm sure you all saw me leave that out and you laughed at me, but that's OK.
I've been left out before and I go back to my Web browser, reload this page, go to the console, cleared
out, OK?
And now I'll try deleting Jack nimble.
So Jack nimble.
No, no, rose in ResultSet.
All right, let's go back here.
Third time is the charm.
If you look at this, I left the slash off of delete and you laughed at me even more mixed up Mixter.
And I'll go back to my front end, where I'm logged in as admin at example, dot com and just to make
sure that user is still there.
I'll go to all users.
There is Jack.
Third time's the charm.
Let's delete this person and Jack is gone.
Perfect.
OK, so Jack has been deleted from the database.
Now let me switch to my other window.
I'm still logged in as Jack and let me go to the admin page menu and choose all users.
First of all, there appear to be no users here.
Let's go to say all sales.
Now, I'm not getting any data, and that's good, but I'm still able to navigate through all of these
things and that's not so good.
So it looks like I have to have some means of ensuring that this user is actually logged out of the
system entirely, because I can still navigate and see things here.
And that's a bit of a problem.
I'm not getting any data, but I shouldn't even be able to see these pages.
So how are we going to figure that out?
Well, we'll take care of that in the next lesson.