So we get some errors, for example here this error, reference error, verify user credentials
is not defined.
Now I actually already see where this is coming from but what you can do of course if you
get errors like this is you can use AI for fixing them.
Now depending on the version you're using you might have a little fix with AI button
here already but if that's not the case you can still highlight this and you should
get a pop-up which allows you to add this to chat.
If you do that you can send this to the AI or say I got this error and well let the AI
help you if you don't know what's causing this error.
In this case the AI tells me that it appears like the verify user credentials function
is being called but it's not defined or imported and the fix is to add the appropriate import
so this import here.
And therefore we can apply this and as you see the only change it makes to this file
is here in the import statement and I'll accept this and therefore this function should
now be available.
So that was a quick and easy fix but it's nice to see how AI can help you with errors
if you don't know what's wrong.
And speaking of not knowing what's wrong we saw before in the previous lecture that
when we created a user we got back an empty user object here in a success response and
that doesn't make sense.
We should get the actual user data here.
So what we could do is manually go through the code maybe we also already know what's
wrong but we can also copy this response here and then bring up the chat, open a new chat
maybe and say when testing the sign up route I got back a success message but the user
data, user object was an empty object.
See below.
Why do I get this response?
And now I'll bring in some extra context.
The user's controller file is already there but maybe it's also helpful to have access
to the model so I'll add this file here and I'll also add the user routes so that I make
sure that the AI will take a look at all these files which hopefully help it understand what
the problem is.
So it takes a look at the code and it correctly identifies that the create user function is
an asynchronous function hence it returns a so-called promise in JavaScript and you
need to await this promise in order to get the actual data yielded by the promise and
we did not do this yet.
So to fix this we need to make changes to the sign up function and await the result
of create user.
So in the user's controller JS file we must add await in front of create user and async
in front of the function keyword here.
So we could do this manually or we click apply and it changes this part here and adds the
async keyword as I mentioned and it changes this part down here and adds the await keyword
and that's exactly what needs to be done so I'll accept this, save this file and we
should be good.
With that if we now close this and if we create another user it should work.
Now if I try to send the same pieces of data especially an email address which was already
used I should be getting an error and I do but if I use a different email address that
should now work again and now I do get back these user details so that is working now.
And for logging in we can give this another try, this now also works.
If I however use an email address that doesn't exist I get an error or if I use an invalid
password I also get an error.
So it's really just the correct credentials that get me logged in.
And that's another huge step forward of course and as you can see we have a nice mixture
of knowledge and AI usage here.
And of course I'm not super fast here because I'm explaining a lot but you could probably
see how fast you could be if you would just be using AI, hitting tab, using chat, using
your knowledge and you would combine all these things to build this kind of application.