00:05
For this, what we're going to want to start by is getting a new ref to house our token's value. So we'll set this as a ref with a type of
00:13
string or null, and we can default it to null. This is only going to be populated after we've created a token, and while we're showing the token
00:21
to the user. Beyond that, token will be null. In addition to that, we can also house whether or not the token is copied via an isCopied flag.
00:29
So we'll set a ref to false there to do that. So after we have created the token and we've gotten that data back, we can go ahead and set the token value
00:37
to our data. and we're passing this back as an accessToken property from our API, and then we're after the token property off of
00:45
our accessTokenDTO. So if we go take a look at our accessTokenDTO real quick to refresh our memory of what we have, we have
00:53
this token property, which is what we're reading from now in view, that contains our token's value, which is wrapped in an AdonisJS secret.
01:01
Again, that secret is there to protect us so that this token value does not get accidentally leaked in something like a log where we are
01:09
not intending it to be leaked. So in order for us to get access to the underlying value of the token, we need to release the secret, which is why we're calling release right there,
01:17
giving us access to that value so that we can plop it into our ref for this next step. Once we've stored the token, we're setting our
01:25
processing flag to false, and we can now go ahead and use Inertia's router to reload. And since we have all of this coming in callbacks,
01:33
we can specify that we only want to reload our accessToken. And that will get us back just a fresh list of only our accessToken, so omitting all of the other
01:41
data from that call. When our token value is populated with something, then within our dialog, we're going to want to show completely
01:49
different contents. So what we have right now, let's add a VELSE onto, and I'm just going to go ahead and copy the entire dialog content
01:57
and paste it up above. So now we have two dialog contents and we'll want to replace the VELSE on the one that we've just pasted in
02:05
with instead a VIF, checking to see whether or not we have a token value. When we have a token value, this dialog content is going to be in charge of
02:13
showing the user their token. So the title for this could be something like accessTokenCreated, and then we can show them a paragraph with
02:21
"Please copy your accessToken below and store it somewhere safe. Once this
02:29
dialog is closed, you will not be able to access your token again." Just kind of warning them
02:37
that they need to get it now or else they won't be able to get it again. Then we can get rid of this form, as we don't need a form for this, and
02:45
instead we can go ahead and show an input field with the token populated. We'll wrap this in a relative div, though, so that
02:53
we can add in a copy button to simplify copying it for the user. So we'll add in a Shotzian input with a type of text
03:01
and set the model value to our token. Underneath that input we can do a button, and then inside of that button we'll add
03:09
in a clipboard check, lose side view next icon. Remember to hit tab to auto-import that, since that's coming from Node Modules. And we'll show
03:17
this when our isCopied flag is true. Just kind of a checkmark showing the user that they've successfully copied their token to their
03:25
clipboard. Set a class width for h4 on that and text green 500. And then when it is not copied, we'll
03:33
just show a clipboard icon, and we'll import that to front lose side view next, and add a velse on for that with a class width for
03:41
h4 so that it's the same size. On our button, we can set this as a variant of outline, set the size
03:49
to icon so that it's square, and let's set a class of absolute right one top one, and let's go ahead and
03:57
force its width to be 8, and force its height to be 8 as well, so that it fits nicely inside of the actual input. We're going
04:05
to overlay it atop of it. So for that we'll set the z-index to 20, and let's go ahead and give it a shadow of empty as well. To make things blend a little bit
04:13
nicer with the input as well, let's go ahead and add just an accent div with a class absolute right one top
04:21
pixel width 32, height of let's do calc 100% minus 2 pixels, the full
04:29
height of the input minus the 2 pixels for the border with a z-index of 10, and a bg gradient to the right, from
04:37
transparent to white. Okay. Lastly for our dialogue footer, we no longer need this button here to be a type of submit
04:45
that can just be a type of button, we no longer need the disabled flag or the form attribute, so we can get rid of both of those, no longer need
04:53
the loader, and we can switch the text to got my token close dialogue, leaving us now with needing @click handlers
05:01
for both our dialogue footer button as well as our copy button right there. So let's jump on up to our script
05:09
and add both of those functions in. So we'll have one function for on copy, and to copy this to the user's clipboard we can use the
05:17
navigator, and it has a clipboard property that we can directly write text to, and for that we'll just write our token value. Once it's
05:25
copied, we can go and set our is copied dot value flag to true, and then we're going to want to set a brief timeout
05:33
so that we can show our is copied checkmark and green indication for maybe about a second and then have it go away.
05:41
So we'll set our is copied dot value back to false after about one second. We can also store that timeout
05:49
so that we can clear it prior to going through that flow, so let's jump back up here where we have our other consts and add in a const for our copy timeout, and
05:57
we'll set this to, I'm not sure if there's an appropriate client side type for this, but we can just use Node.js's timeout type
06:05
that will suffice, or null, and then default it to null. We don't need this to be a ref, we don't need it to be reactive in any way, we just want to store that value.
06:13
So with that copy timeout set, we can assign that to the return of our set timeout so copy timeout equals, and then prior to our on copy
06:21
we can go ahead and clear timeout copy timeout. Now let's check our red squiggly here. Oh, I sure did, I assigned it as a const, didn't I? So we'll switch this to a let
06:29
and I always like having my consts all together, so we'll move that up to the top. Okay, and then this is probably because it's nullable, yep, so we can go ahead
06:37
and do if copy timeout, should make that happy, and then we can also do an additional check to see whether or not we have a token value, and if we do
06:45
not, then we can go ahead and just return, as there's nothing to copy, you can also show some kind of message to the user to let them know that something's not quite right,
06:53
but that should let us get rid of the exclamation point on our token value there with our write text. Alright, the next function that we want to add in then is on
07:01
the close function for when we're closing our dialog. Whenever we close that dialog we want to set our is dialog shown value to
07:09
false, which will hide that creation dialog that we've been working with. We also want to set our token value back to null
07:17
to clear that out of memory, and that should do it. So let's go rig both of these up. So let's jump down to, back into our token dialog content
07:25
where we have our clipboard button, so we'll do @click and set that to on copy, and then we have our dialog footer
07:33
button, which we can set an @click for on close. Okay, so we should be all set with that flow, I believe.
07:41
So let's go ahead and try it out. So that we go ahead and get our third token showing up here within our list, we'll go ahead and refresh real quick, and then we can add
07:49
access token. We'll call this test04, hit create access token, and voila, there is our token with our
07:57
message, please copy your access token below to store it somewhere safe. If we click on our copy button, we see that we get our little check mark there for about a second,
08:05
and then it goes away, and I can click got my token, and if we come back over to our text editor and I paste, there is our copied token. So
08:13
if we go ahead and right click, go down to inspect, and let's dig into the Vue.js dev tools here. So, view there. Now if you don't
08:21
have this installed, you can go into your browser of choices extension store, and there should be a Vue.js dev tools that you can install there,
08:29
and have it show up here within your web dev tools. Let's drill into our page, should be our organization page here, and let's just take a look at our access token.
08:37
So if we take a look at the first one, here's our test04, you can see that it has an abilities array of just read, and most notably here we don't have our token property
08:45
with that actual token value that we copied. As stated before, that's only going to be populated whenever we create the token, which is why we warn our users to make sure that they have
08:53
it copied and stored somewhere safe for usage. So if we take a look at all of them, all of them reflect the same kind of format where they don't have that token. And the one that we
09:01
just created doesn't have that token, which is our test04, because we've refreshed this table's contents from our database via
09:09
that refresh call that we have within our onSubmit handler right here. So this array has already come back from our server,
09:17
and since we've cleared our token value out, after we've copied, when we've closed the dialog, we no longer have that token in memory at all anymore
09:25
at this point in time. Alright, before we round out this lesson, I need to get rid of that paste that I pasted in here with my token. There we go, alright.
09:33
Now we're good to move onward. Our next step is to allow us to delete a token. We have a number here to work with for that.