So we have the form displaying properly and of course, now we need to populate it with information
for an existing user and that's pretty straightforward.
So let's go over to Route's Dash API, which is what we'll be calling using fetch from our front end
and here in the protected section, right after all, users.
I'll add a route to a non-existent handler which will create in the moment.
I'll make it a post route and it will be to add apps and all dash users and then some ID and we'll grab
the ID as necessary, of course, and then we'll go to app, say, one user, which doesn't exist.
So let's go create that over in handler dash API right here at the bottom.
We'll create a function.
I'll just copy this one to save some time and paste it in there and make this one user.
And of course, we need to grab the I.D. from you URL, so as is a sign the value of you are program
and we're going to hand it our.
Which is our request and we're looking for it, and we'll convert that to an INT, which I need it to
be in user ID, not ignore the error and you shouldn't is assign the value of Sterkel to I and we're
going to convert it.
And once I have that, I'm going to call, not get all users.
Instead I'll call that and get one user and handed the ID user ID and will remain this variable to say
user and we'll handle the user.
So that should work for the backend, that should get the ID, go to the database, grab the user ID,
convert it to Jason and write it to the end user.
Now back here on one user page Dutko HTML of course.
We need to call that, and that's as simple as adding in some script tags
and putting in a document at event listener.
And our condition is dom content loaded
and we'll execute this function.
Now the first thing we're going to do, of course, is get our token, let token equal local storage
yet item.
And we're looking for token.
And we also need to get the ID from the URL and we've already done that.
It's as simple as it is equal to or let into equal window, location,
path, name, dot split.
And we're splitting on the slash and we pop and that gives us even the URL.
Now we create some request options
and we're going to have a method post, which is what we set our route to and our headers and the sender
would
accept
an application duration
content type.
Also, application, Jason, Jason, and authorization.
Which would be better space and our token.
Now we just call, fetch, fetch, and we're going to fetch to the API route, which is hand hand it
to every templated in our system, apress it, all the users slash and then append ID to it and handed
the request options and I better close that properly.
Plus I request options.
Then we convert our response to Jason.
Then and for right now, we'll just say function data.
Let's just write things to the console to make sure it works, console dialogue, you know, OK, let's
start everything, Mr..
Go back to your Web browser, open our console login
that mean at example dot com
password and once login and go to admin all users and click on user.
And over here, I get an object with an idea of one first name and last name user, there's the email
and the password is set to empty, as it should be, since we never populated it.
OK, so the next step is simple.
We simply grab the information from our Jason and populate this form, and we'll take care of that in
the next lecture.