1 00:00:00,620 --> 00:00:09,060 Well, in the last video we stayed in the lockout, we created the token, 2 00:00:12,060 --> 00:00:21,739 we converted it to a cookie, we sent it to the front, then we verified with the lockout 3 00:00:21,739 --> 00:00:29,320 that the token was left at zero. The previous video was a bit about the creation of this 4 00:00:29,320 --> 00:00:36,159 touch now what we are going to do is if we have created a touch in which it is for security 5 00:00:37,200 --> 00:00:44,079 because we are going to use it we are going to see the way to use it is worth then 6 00:00:46,159 --> 00:00:59,079 we are going to make a new route that for example is that and it is because with this that there is always 7 00:00:59,079 --> 00:01:05,459 a user who logs in, who registers and such, the profile is always there, not the user's profile, 8 00:01:05,459 --> 00:01:12,280 so here we are going to make a new route router point in this case we are going to put the protocol 9 00:01:12,280 --> 00:01:27,019 get and we are going to call it profile we have said profile ok here we are going to execute a function 10 00:01:27,019 --> 00:01:37,219 the same as in the previous routes, it is worth and then that function we are going to do it within 11 00:01:37,219 --> 00:01:42,640 out controller as we have been doing so far now well what I want to do here 12 00:01:42,640 --> 00:02:00,620 is also to create a middleware, it is worth that this is a function that we put before the function is executed 13 00:02:00,620 --> 00:02:08,020 that we want within the app and within the server is not a function that is fulfilled 14 00:02:08,020 --> 00:02:16,460 or not, if it is not fulfilled, the function that we have in controller will never be executed, it is worth that 15 00:02:16,460 --> 00:02:23,979 generally it will access a database or read a file or a json or whatever is worth 16 00:02:23,979 --> 00:02:30,699 then that intermediate function is what is called a middleware is worth then 17 00:02:30,699 --> 00:02:43,000 to do this we are going to use the midware folder, so there we are going to create a file, 18 00:02:43,000 --> 00:02:50,509 we are going to see what we are going to call it, for example, you already know that the name is that you can give it 19 00:02:50,509 --> 00:03:01,069 as you want, I am going to call it validate touch point js is worth always js which is what 20 00:03:01,069 --> 00:03:12,469 we are working with not ok well then here I am going to create a function that we are going to call 21 00:03:12,469 --> 00:03:20,569 for example we are going to put how we are going to export verification for example it is worth verifying 22 00:03:20,569 --> 00:03:32,689 que va a recibir un rey un res como siempre vale pero ahora además va a recibir un parámetro nuevo 23 00:03:32,689 --> 00:03:43,550 que es next vale next lo único que hace es que vaya a la siguiente función es decir vamos a 24 00:03:43,550 --> 00:03:48,050 to put this here we are going to put 25 00:03:48,050 --> 00:03:51,050 here I am missing 26 00:03:51,370 --> 00:03:54,889 we are going to put here 27 00:03:54,889 --> 00:03:58,689 with only a point 28 00:03:59,610 --> 00:04:02,930 a point 29 00:04:03,509 --> 00:04:09,310 that does not visualize this ok then we have a function inside our 30 00:04:09,310 --> 00:04:13,169 file that will be in my network will have to execute this 31 00:04:13,169 --> 00:04:22,050 function before executing one that we are also going to create now, which is the one that would be 32 00:04:22,050 --> 00:04:28,290 inside the server, then the one that would be inside the server would be inside the controller, 33 00:04:28,290 --> 00:04:36,750 then inside the controller we are going to create a function that is sport with 34 00:04:36,750 --> 00:04:48,089 profile this is going to have a network as always a network is worth this is going to have 35 00:04:50,470 --> 00:04:53,149 the arrow function in which we are going to say for example 36 00:04:57,689 --> 00:05:00,810 that is, the point 37 00:05:00,810 --> 00:05:12,810 that we visualize here anything is worth just to do the test we are going to put a message that 38 00:05:12,810 --> 00:05:25,220 is going to be because profile is worth for example something like that then we have our constant function 39 00:05:25,220 --> 00:05:32,120 in our arrow function the profile is worth that it is on the route that we want to execute 40 00:05:32,120 --> 00:05:41,680 profile ok when we call this route ok now I'm not going to put the middleware one 41 00:05:41,680 --> 00:05:53,980 I'm going to leave it like that because here I would also need to import profile ok ok then what I have 42 00:05:53,980 --> 00:06:02,379 also done in app js is to add the white line is worth then I have changed it is to those 43 00:06:02,379 --> 00:06:11,980 points to access them is worth then if we take we come to our 44 00:06:11,980 --> 00:06:21,920 client here we are going to not request we are going to put local house 45 00:06:24,980 --> 00:06:37,019 4000 and profile is worth with the one that because we have put that then it will return the profile to me, it 46 00:06:37,019 --> 00:06:45,779 okay, it tells me 200, that is, it is doing everything well, it is doing everything well, okay, now we continue 47 00:06:45,779 --> 00:06:53,339 with our middleware, which is valid, validate, touch in js, okay, we have it done here, the only thing 48 00:06:53,339 --> 00:07:01,240 I want is for me to visualize the body network here, okay, then in the routes now I am going to put 49 00:07:01,240 --> 00:07:10,899 here that function then this function is inside validate token then the first thing 50 00:07:10,899 --> 00:07:14,240 I have to do as we have been doing always is the import 51 00:07:19,980 --> 00:07:30,230 validation we have called validation verification verification 52 00:07:30,230 --> 00:07:44,110 ok I already have it here and then here I am going to pass verification ok ok we press the shift to the 53 00:07:44,110 --> 00:07:53,389 efe so that I put everything right ok then in verification we have it to view 54 00:07:53,389 --> 00:08:00,110 by console the rey body and then it goes to the next to the next function that would be 55 00:08:00,110 --> 00:08:08,029 worth the one that would be profile it would be the one that is already running within the controller that is 56 00:08:08,029 --> 00:08:17,389 inside the api server or the backend ok then if we go here I give it to be it gives me the profile again 57 00:08:17,389 --> 00:08:24,230 esto me lo da en blanco porque no tenemos no hemos enviado ningún dato 58 00:08:24,230 --> 00:08:30,990 vale por eso me lo da en blanco si cogemos y nos logramos 59 00:08:31,269 --> 00:08:36,470 pom pom vamos a poner por ejemplo este es lo 60 00:08:36,470 --> 00:08:42,190 how login vale tenemos a carmen que lo teníamos creado villablanca dando se 61 00:08:42,190 --> 00:08:51,970 ok now we have it activated if we click on the request well for now it doesn't give me anything 62 00:08:51,970 --> 00:08:58,090 ok then we are going to put it here to see it well instead of the rec body that 63 00:09:00,830 --> 00:09:04,250 because we are not taking anything we are going to put a 64 00:09:04,250 --> 00:09:30,289 y pues un mensaje función verificación vale y entonces aquí ahora si le damos al sen vale 65 00:09:30,289 --> 00:09:35,230 ya si me pone la función verificación vale esto sólo es para ver que nos está que primero estamos 66 00:09:35,230 --> 00:09:42,169 entrando en función verificación y luego estamos entrando en el portal vale vale por ahora está 67 00:09:42,169 --> 00:09:55,470 everything is fine, well then now what I am going to try is first to generate a cookie, okay, we have 68 00:09:55,470 --> 00:10:04,309 left that when we do a login, it is worth it, it creates this cookie for us, so I need to take this 69 00:10:04,309 --> 00:10:12,470 value that is the touch to then verify we remember from the previous video that this touch carries 70 00:10:12,470 --> 00:10:25,549 the load the load value is valid it carries the user id and then we can extract it from here 71 00:10:25,549 --> 00:10:35,269 but we need within the function of validate we need to take this information that 72 00:10:35,269 --> 00:10:41,110 we have in heads or we have it in cookies, it is worth taking that information and 73 00:10:42,990 --> 00:10:54,590 comparing or extracting in some way or verifying through our secret field 74 00:10:54,590 --> 00:11:07,929 ok of the one we have saved in config ok here remember that we saved the password the secret word 75 00:11:07,929 --> 00:11:17,529 the secret touch to be able to encrypt that token ok and sign it digitally then a little 76 00:11:17,529 --> 00:11:22,710 the idea is this we have to extract this to then compare it and see if that idea exists in the 77 00:11:22,710 --> 00:11:28,389 database then the first thing I have to do is try to extract this ok let's see how 78 00:11:28,389 --> 00:11:35,570 we can do it ok then this I'm going to delete this I'm going to put it down here well then 79 00:11:37,250 --> 00:11:49,909 we can put a console dot log and we can put network ok it is the request is what 80 00:11:49,909 --> 00:12:00,289 reaches us from the front to the back end and we are going to try to work with the head ok then with 81 00:12:00,289 --> 00:12:06,250 the head it will return us different information then we are going to try to take the head is ok 82 00:12:06,250 --> 00:12:16,950 then this would be where we are here red dot head is ok and to see this if it shows us something 83 00:12:16,950 --> 00:12:22,009 in principle it does not seem that it is giving us any error which is very good then 84 00:12:24,149 --> 00:12:31,649 we go back to the profile I give it to the senf and it returns the heads and one of these 85 00:12:31,649 --> 00:12:39,470 returns me a json with some keys and some values one of them is this one of cookie okay 86 00:12:39,470 --> 00:12:50,149 entonces esto va por buen camino si cogemos y aquí ponemos punto cookie a ver que nos devuelve esto 87 00:12:50,149 --> 00:12:58,850 esto en principio entiendo que me va a dar a no me funciona bien vale crea que tenía que extraer esa 88 00:12:58,850 --> 00:13:04,110 variable pero si lo puedo poner así me funciona bien vale esto me devuelve esta cadena que pone 89 00:13:04,110 --> 00:13:13,049 touch me the same and it puts me all this information is worth it is not the touch because it already puts me the touch 90 00:13:13,049 --> 00:13:21,330 the same good we could work with the strings separate to the same good but of course we also have 91 00:13:21,330 --> 00:13:29,889 this cookie entry is worth this entry when I do a login it also has that information 92 00:13:29,889 --> 00:13:37,210 ok then and I already have it in key value format then somehow to see if we can 93 00:13:37,210 --> 00:13:43,750 access these cookies then we come to validate and I say good because what I want is instead 94 00:13:43,750 --> 00:13:53,529 of having to see let's see if I can access cookies to cookies ok then with only cookies ok we come 95 00:13:53,529 --> 00:14:05,230 and it tells me that it is undefined, okay when we know that the cookie is created but it does not 96 00:14:05,230 --> 00:14:11,909 recognize it to me this is because we need to install we need to work with the cookie 97 00:14:11,909 --> 00:14:21,370 parser, that is, if you remember when we tried to put the first json, we had to load the 98 00:14:21,370 --> 00:14:34,129 json file in app ok we told him to use the express point json that came with the express ok 99 00:14:34,129 --> 00:14:39,990 then here we have to do something similar to recognize that format of the cookies there 100 00:14:39,990 --> 00:14:56,070 que hay que instalar un módulo de de note que se llama vamos a parar esto que se llama en el pmi 101 00:14:56,070 --> 00:15:06,230 y este se llama el cookie punto para ser vale cookie y perdón punto cookie guión medio parce 102 00:15:06,230 --> 00:15:16,570 here we install it, it is now we are going to import it as always import we are going to put it 103 00:15:19,289 --> 00:15:32,970 we are going to put it to be better from 104 00:15:32,970 --> 00:15:48,820 ok and we are going to tell the express app to use that format, it is worth then 105 00:15:50,860 --> 00:16:02,399 and now we are going to try it once we have put this then we are going to launch 106 00:16:02,399 --> 00:16:16,360 our express we already have it here we are going to log in he has created a cookie with the touch we go to the 107 00:16:16,360 --> 00:16:26,200 profile I give it to sense and then now I already have the token field and the key touch and the value with 108 00:16:26,200 --> 00:16:32,860 the touch exclusively with this, it is no longer working well, okay, but now what I want 109 00:16:32,860 --> 00:16:41,700 is to extract that value then instead of putting with only what I am going to say is good because I have 110 00:16:41,700 --> 00:17:00,389 a constant touch that is going to be the same as the network point is worth and there I am going to save that value we are going to 111 00:17:00,389 --> 00:17:09,920 see it then this as here this one I put a console point the touch 112 00:17:12,079 --> 00:17:27,720 is worth we are going to test it I press the indefinite sense here it tells me indefinite because we are going to see 113 00:17:27,720 --> 00:17:34,519 constant touch that I have written very badly 114 00:17:36,319 --> 00:17:54,950 now we are going to give it a format ok let's see now if I go to the center it tells me it is not defined touch it is not defined 115 00:17:54,950 --> 00:18:10,529 this is not defined this is in plural then it is in plural this is 116 00:18:14,430 --> 00:18:21,789 now if we have it ok I already have it saved in touch the touch the three groups of 117 00:18:21,789 --> 00:18:33,250 cifras y letras vale que una tiene la carga el valor de carga otro tiene el tipo y el algoritmo 118 00:18:33,250 --> 00:18:40,170 que hemos usado el otro la otra parte de la firma digital vale acordaros de todo eso vale pero ya 119 00:18:40,170 --> 00:18:47,910 tengo todo esto lo cual está muy bien vale y sigo jugando con mi función verificación entonces en 120 00:18:47,910 --> 00:18:53,910 instead of putting a console that I already use to verify only that I am saving there is a data what 121 00:18:53,910 --> 00:19:02,920 I am going to say is good in the case that there is no touch is worth that touch in this void then 122 00:19:02,920 --> 00:19:07,279 what is that going to mean that that user that verification that I am doing that has been 123 00:19:07,279 --> 00:19:14,559 registered is worth and how it has been logged or it has been registered it has been registered that cookie has been created 124 00:19:14,559 --> 00:19:21,799 if not, it is not worth it is a user who is trying to access a link that 125 00:19:21,799 --> 00:19:25,839 cannot because it is not logged then here we are going to return a retun 126 00:19:31,940 --> 00:19:47,150 3 status point 400 for example we are going to put a point json and I am going to pass it 127 00:19:50,990 --> 00:19:57,789 that the user is going to be 128 00:20:01,450 --> 00:20:03,809 ok ok 129 00:20:05,849 --> 00:20:12,970 and if we don't continue ok then we're going to try it now we're going to write 130 00:20:12,970 --> 00:20:21,490 a good one for the client we had the lockout ok we are going to launch the lockout 131 00:20:23,009 --> 00:20:34,930 and I am going to remove this user who has good now he does not have a cookie but now 132 00:20:34,930 --> 00:20:41,349 it will be cleaned if I try to log in now or see the profile enter a profile without being 133 00:20:41,349 --> 00:20:48,990 logged here it is going to return us the state 400 is worth 134 00:20:52,549 --> 00:21:07,039 here I have done something wrong I understand now if the user is not logged it is worth what he was looking for 135 00:21:07,039 --> 00:21:21,920 user is not logged, okay, if now we log in as Carmen, okay, we go back to our profile and 136 00:21:21,920 --> 00:21:29,180 since now that cache does exist, okay, we have created a cache and a cache, sorry, a cookie with 137 00:21:29,180 --> 00:21:38,299 that touch when we come to profile if I give it absentee so I get the profile because it has already 138 00:21:38,299 --> 00:21:46,299 passed that middleware has verified that within touch if there is a there is a data there is a touch 139 00:21:46,299 --> 00:21:55,519 ok then it allows me to continue ok ok now if I have a touch there I already have that touch 140 00:21:55,519 --> 00:22:02,720 what I have to do is verify that the value load that goes 141 00:22:02,720 --> 00:22:11,359 inside the token, which is the ID, exists within my database, because if not, that 142 00:22:11,359 --> 00:22:16,200 token I can make a cookie, generate a token that is more or less similar to that and deceive 143 00:22:16,200 --> 00:22:23,920 this app and this backend. So we have to verify that it exists within the database. 144 00:22:23,920 --> 00:22:32,740 then for that jason web talking has a function that is very verify is worth the verification 145 00:22:32,740 --> 00:22:50,720 is worth then what I have to do is import import jw from jason web ok first I have to 146 00:22:50,720 --> 00:23:01,680 do this ok then if it touches it exists here we are going to create ourselves or we are going to use that 147 00:23:01,680 --> 00:23:15,000 function that I am telling you I am going to verify ok ok and this one has three entry parameters 148 00:23:15,000 --> 00:23:18,900 one is the touch that we already have we just got it and I have it saved in the 149 00:23:18,900 --> 00:23:27,779 variable touch is worth another is the secret key or if we have used remember with the jw t we could 150 00:23:27,779 --> 00:23:37,380 use the pair of keys the pair of keys is worth the public and private in this case in our case it 151 00:23:37,380 --> 00:23:49,819 is only a key that we had in fixed point js and then a function some options that is a 152 00:23:49,819 --> 00:23:56,039 verification function that passes me a complete that is going to return me a true or a false valid then 153 00:23:56,039 --> 00:24:06,500 we are going to take a true or because it is an error or a complete ok then we are going to start with this 154 00:24:06,500 --> 00:24:15,240 first parameter the touch ready touch second parameter the secret key that we have to 155 00:24:15,240 --> 00:24:27,960 import ok and this is touch touch secret ok I already have it here then we are going to pass it 156 00:24:27,960 --> 00:24:45,799 ok third parameter that function then this function function you are going to receive a 157 00:24:45,799 --> 00:24:55,640 track and you are going to forgive a reg not an error ok it is going to give me an error or it is going to give me a 158 00:24:55,640 --> 00:25:11,720 worth a decoding is worth in error because it would be if an error has occurred at the time of decoding 159 00:25:11,720 --> 00:25:18,920 this this touch that we have taken out of the cookies is worth if some type of error occurs 160 00:25:18,920 --> 00:25:28,099 but I already tell you that jw t is a structure then it has not if you invent a token 161 00:25:28,099 --> 00:25:32,240 because it will fail ok then an error will occur and this will save it to me here 162 00:25:33,759 --> 00:25:43,019 and if it manages to decode it the same as on the page of jw point and or when we copied the 163 00:25:43,019 --> 00:25:53,220 token and we put it there it is worth then it will return the document it will return a document 164 00:25:53,220 --> 00:26:01,259 here it will return the value load the pilot is worth that we are going to see it now well what 165 00:26:01,259 --> 00:26:08,039 I am going to do here is an arrow function then this function I am going to remove it from here 166 00:26:08,039 --> 00:26:17,119 and here I am going to put my arrow function, okay, then it is here, 167 00:26:19,119 --> 00:26:31,299 then what we have said if this arrow function if it returns me an error then yes 168 00:26:32,819 --> 00:26:39,579 error that is what I am going to do return there I cut it ok there it would stop and return a 169 00:26:39,579 --> 00:26:49,119 state 400 for example the return as always we send to the throne a status status 400 170 00:26:51,059 --> 00:27:03,650 ok we send a json in which we are going to put a message and we are going to tell him that something like 171 00:27:03,650 --> 00:27:17,450 the touch is invalid, something like that, okay, and if the touch is fine, then we are going to 172 00:27:17,450 --> 00:27:32,539 start doing some test with this, then we are going to and we are going to print to see that it returns us 173 00:27:32,539 --> 00:27:46,440 to see what information there is inside the code is worth for you to see it is worth then a little 174 00:27:46,440 --> 00:27:54,240 recapping a little what we are doing is worth and this next would no longer be out here because 175 00:27:54,240 --> 00:28:03,940 to be here, this would be the next one because it is there because I am putting everything 176 00:28:03,940 --> 00:28:10,240 within the arrow function, which is the one that will decide if the touch is correct or not, it is correct 177 00:28:10,240 --> 00:28:17,299 if it is correct then you are also going to print it by console, you are going to go to the 178 00:28:17,299 --> 00:28:27,180 function that we have within the control is worth then I come here I launch it and 179 00:28:29,880 --> 00:28:34,250 to see that I have failed here 180 00:28:36,509 --> 00:28:44,500 we are not going to find we are going to see because this is sure that I have forgotten when you are telling me this about the 181 00:28:44,500 --> 00:28:52,960 file that you do not find it or is that I have forgotten the js that indeed the config.js 182 00:28:53,660 --> 00:29:04,099 ok we are ok we are here sense and then look how we were logged yes it returns me 183 00:29:04,099 --> 00:29:12,420 the pilot and in the value load yes it returns me this identifier and then it returns me these 184 00:29:12,420 --> 00:29:18,920 two values ​​that accompanied in the value load that right now I do not use them at all I only 185 00:29:18,920 --> 00:29:27,299 me hace falta este identificador vale entonces a ver ahora cómo sacamos este identificador de 186 00:29:27,299 --> 00:29:36,779 aquí si cogemos y hacemos un log out vale ya no hay ya no hay cookie debería ser entonces me va 187 00:29:36,779 --> 00:29:43,200 a decir el usuario no está logueado vale el jota son que le hemos enviado lo cual no se está 188 00:29:43,200 --> 00:29:51,119 working well ok ready we are going to log in again we already have it and there we have to 189 00:29:51,119 --> 00:30:01,019 see how we get this one is only the identifier ok then we are going to keep playing a 190 00:30:01,019 --> 00:30:09,059 bit ok we have seen that it is returning it to me within the pilot ok if I put here 191 00:30:09,059 --> 00:30:22,319 by loathe decoded point by loathe ok let's see what happens here then if I give it to the 192 00:30:22,319 --> 00:30:29,819 center ok now it only takes me out this json with this value key ok and I am approaching the 193 00:30:29,819 --> 00:30:37,700 goal which is to stay only with this idea then to stay only with that idea let's see if 194 00:30:37,700 --> 00:31:00,640 I put here .id, I give it to the send and here I have it, okay, this would have different ways of doing it, I can do it like this, I can do it, tell it, okay, well, create a constant that is called, for example, identifier, or as you want, okay, 195 00:31:00,640 --> 00:31:07,099 the same as here and here I can put the names that you want, it is worth the code error, these are 196 00:31:07,099 --> 00:31:16,099 the ones that are usually put but you can use the ones that you want, it is worth then constant 197 00:31:16,099 --> 00:31:26,539 identifier this is equal to and this is a variable then here we are going to put the keys that 198 00:31:26,539 --> 00:31:35,960 I always forget and here I am going to put the decode dot pilot dot and d 199 00:31:37,220 --> 00:31:46,069 because I am going to extract the identifier so here now we put the point and comma 200 00:31:46,069 --> 00:31:52,329 if here now I put the console.log 201 00:31:53,630 --> 00:31:59,690 identifier ok this in principle is going to do exactly the same then 202 00:31:59,690 --> 00:32:02,809 let's see 203 00:32:03,490 --> 00:32:10,750 and he tells me that it is undefined let's see why 204 00:32:10,750 --> 00:33:05,849 constant identifier ok the error is this we are going to see it is I am going to put the console again 205 00:33:05,849 --> 00:33:12,470 what I had before ok I am going to comment on it is to comment ok we have this here if we give the 206 00:33:12,470 --> 00:33:20,029 I get the id. What happens? What am I doing wrong with these two lines at the bottom? 207 00:33:21,410 --> 00:33:27,089 Okay, I put constant and I want to bring the identifier variable, okay, but that variable 208 00:33:27,089 --> 00:33:35,990 does not exist. I can't put identifier, I'll have to put id, okay, which is the field, the key, 209 00:33:35,990 --> 00:33:45,539 que sí que está dentro del país lo hace si yo ahora aquí visualizó y de pues esto sí me va 210 00:33:45,539 --> 00:33:53,920 a funcionar pero vale ahí lo tenéis pues esto lo puedo hacer de estas formas ahora yo lo que 211 00:33:53,920 --> 00:34:03,920 quiero es vale esta es mi función de verificación estaba a verificar el qué hay en una cookie con 212 00:34:03,920 --> 00:34:12,800 an identifier, okay, but the rest of the functions that I have inside, because in this case the profile one 213 00:34:12,800 --> 00:34:20,420 also has to have access to that identifier, okay, then we can use the reg itself, 214 00:34:20,420 --> 00:34:28,880 okay, the request, the information that the data collection that the front sends us 215 00:34:28,880 --> 00:34:40,639 the front allows us to create keys to us and add a value to them, it is worth then that here 216 00:34:40,639 --> 00:34:51,260 what I can do is once I have extracted that idea I can say network point and I believe I invent a 217 00:34:51,260 --> 00:34:56,599 key is worth the one that you want, for example, since I had put the identifier before, 218 00:34:56,599 --> 00:35:09,719 pues venga identificador esto va a ser igual a y de vale entonces ahora si nos fijamos en 219 00:35:09,719 --> 00:35:17,400 controles todos tenemos acceso a red vale y todos es lo mismo entonces lo que le estoy diciendo es 220 00:35:17,400 --> 00:35:23,400 bueno pues sí sí todos tenemos acceso a red que si yo creo una variable que se llama identificador 221 00:35:23,400 --> 00:35:33,780 a key that is called identifier within the network and there I assign it is that touch is worth we can 222 00:35:33,780 --> 00:35:42,219 from anywhere verify that touch is what we are going to do this this function we would already 223 00:35:42,219 --> 00:35:49,719 finish it here and we now go to the controller and in the controller instead of putting the 224 00:35:49,719 --> 00:35:58,579 profile, we are going to start working with it, which is the first thing I am going to do, then 225 00:35:58,579 --> 00:36:07,900 see if it is an identifier that we have saved within the network, it is found within our 226 00:36:07,900 --> 00:36:15,099 database or not, it is worth remembering that to launch a consultation against the database I need 227 00:36:15,099 --> 00:36:22,480 mongoose is worth everything that is with against the database I need it to be mongoose 228 00:36:23,820 --> 00:36:29,800 then we are going to and we are going to create a 229 00:36:31,739 --> 00:36:42,920 a consultation that would be with jose that is the one that we import from the model that the model and the 230 00:36:42,920 --> 00:36:48,079 the scheme, remember that we did it with mongoose and then we can launch the 231 00:36:48,079 --> 00:36:58,760 consultations with you, and in fact when we did the login we had spy one, okay, and well, we have 232 00:36:58,760 --> 00:37:04,760 done this with query but here you have the user point web is where we draw that consultation here I 233 00:37:04,760 --> 00:37:13,980 I'm going to do it directly, this would be here, not here, and here I use a point, 234 00:37:15,679 --> 00:37:24,519 okay, what do we want to do, find a user for their air, then fine by air, 235 00:37:24,519 --> 00:37:32,260 there you take it, okay, and what is the idea that we have saved in network point and sorry and 236 00:37:32,260 --> 00:37:43,059 identificador identificador que para eso la hemos creado vale entonces esto me va a devolver un 237 00:37:43,059 --> 00:37:57,019 usuario si lo encuentra o no vale pues aquí le voy a meter un constante usuario es igual a user 238 00:37:57,019 --> 00:38:03,340 fine by aire y como es una consulta a base de datos esto lo vamos a hacer asíncrono así que 239 00:38:03,340 --> 00:38:10,599 here I am going to put the weight and as the wave you have to remember that it always accompanies the 240 00:38:10,599 --> 00:38:23,849 zinc, it is worth if the user if it is empty, which is what it means that I have not found this 241 00:38:23,849 --> 00:38:29,670 identifier that this identifier does not exist in our database with what is not registered in the 242 00:38:29,670 --> 00:38:43,349 base of data now we are going to send a res status a retun res status we are going to put the 400 243 00:38:45,010 --> 00:38:45,949 json 244 00:38:48,949 --> 00:38:58,699 keys and here we put an unregistered user for example 245 00:38:58,699 --> 00:39:06,300 ok for example user unregistered ok and 246 00:39:09,340 --> 00:39:13,659 well if the user has found it then now what I'm going to do is 247 00:39:13,659 --> 00:39:21,199 directly print it to me and that's it then we're going to send it to the network that sends it to us from json 248 00:39:21,199 --> 00:39:33,900 and in the json I am going to say that it puts me usual ok and then here you see that this variable 249 00:39:33,900 --> 00:39:39,519 that we have created identified that has the idea I am using it in the controller to pass it on 250 00:39:41,519 --> 00:39:48,619 to the database to the search is worth to the query of the database is worth in principle if not 251 00:39:48,619 --> 00:39:57,760 this if everything is fine because it is already then we go first this is the out so nothing we go out 252 00:39:59,179 --> 00:40:08,619 ok here I give it to send ok the user is not logged we log in ok now we already have a cache 253 00:40:08,619 --> 00:40:17,719 and when I come here it is ok and it already returns me all the values ​​all the key value document 254 00:40:18,619 --> 00:40:24,860 that belong to the identifier that we have taken in the middle where it is worth then a 255 00:40:24,860 --> 00:40:34,400 video web a middle where it is used for that it is worth to be able to do verifications it is worth the 256 00:40:34,400 --> 00:40:40,760 next the next all that you are going to see always in the middle where it is worth especially when they are 257 00:40:40,760 --> 00:40:50,460 de verificación vale bueno qué es lo que faltaría hacer ahora que estamos trabajando contra contra 258 00:40:50,460 --> 00:40:58,699 una base de datos vale entonces aquí lo suyo es usar el try el cat bueno la web ya lo hemos 259 00:40:58,699 --> 00:41:06,500 usado entonces esto ya os lo dejo como ejercicio para vosotros y en el siguiente vídeo ya os enseño 260 00:41:06,500 --> 00:41:13,440 as it would be worth then that yes that for you to follow a pattern remember when we have 261 00:41:13,440 --> 00:41:24,940 done that with register it was it seems to me to create token access it is worth creating token access it is 262 00:41:24,940 --> 00:41:32,739 in lib jwt this function was here then put another one here that is called token verification 263 00:41:32,739 --> 00:41:35,340 o algo así vale y que nos vaya a devolver 264 00:41:38,079 --> 00:41:44,320 que nos vaya a devolver pues la información vale lo que estamos haciendo no poner aquí 265 00:41:44,320 --> 00:41:54,039 esta consulta y todo esto vale bueno pues pues hasta aquí un saludo hasta luego