All right, so let's go ahead and dive into user authentication. All right. Okay, so first let's talk about registering a new user. Okay, so so far all we did is we didn't leave our schema and we just created a custom result or function. Now, let's take a look at how we can create a custom resolver in FQL that will allow us to register users. Okay, now this function is a function that takes an email, password and username and then saves the user information in Flutter. Here, you'll see that there is a credential field. So by saying that this password is a credential, Fauna knows that it's a password and it shouldn't be revealed, okay? So that's very important because you don't want your passwords to be revealed, right?
Okay, so registering a new user, so let's go ahead and create a new function and call it registerUser. So let's go to a function, From this create a new function, it registerUser, we had to do this, copy this. All right, let's say it over here. All right, so query and Lambda, these two keywords are just used to define the function. And here you have an array of arguments. Alright, so email, password, and name, these are the three arguments that is passed in this Lambda function. Creates, so create keyword, we're defining that, okay, we wanna create something new, we're gonna create a document. Collection, which collection, we wanna create a document in the owner collection. Credential, so, and then this bracket, in this part, we're just defining, okay, how we're gonna store the data. So first, with the credential keyword, we're saying, okay, password, there's a password field, treat it as a credential, and then the rest of this is data, so treat it as variable, email variable and the new variable. All right, so let me take a look at here. Okay, all right, so, let's save that. Okay, so now, I'm gonna show you something called Fonachelle. So we created this user, registered user function. Now, we can go ahead and create a mutation and add the mutation and call our GraphQL but it's kind of a hassle to upload the function every time. I just wanna test my login function pretty much. So how do I do it? So I can just go to shell here. Let's go to shell. And here, I can call that PDF, okay. All right, so I can do it with Paul and then the name of the function. And I think we had, so email, password, and first name. It's going to cheat a little bit. And pass in the array, so this is, okay, so this array is mapped to these parties. So now we can kind of make that connection now. All right, okay. And now, let's run it. It is successfully saved, so let's verify. This is our data. And as you can see, you're not gonna see the password field. So just because we defined that the password is a credential type, while you can see the password, that's password 123456. Just because we defined the password credential type, it's not saved explicitly in the database. So if I wasn't smart enough to know that, okay, this is a credential, then I'm gonna expose it. All right, awesome. Okay, so if we have that, and by the way, everything that I'm talking about in this workshop is going to be in our GraphQL workshop website, and we're gonna be continuously updating this and refining it. So feel free to check it out after the workshop, everything is there. We even gave you guys the ability to download these schemas separately if you wanted. So for example, this is just gonna download schema up to this point. All right. All right, so... Okay, so you guys know the drill, so we're gonna create, we're gonna make some changes in our schema again and hook that UDF user defined function to a mutation. Right, so, just copy and paste it. All right, so, excuse me. All right, so we're gonna call it register owner. We're gonna give it an email, which is a string type, password also a string type and a name. Okay, and it will return an owner type. And we have the resolver keyword, just like before. And then the name we're saying, this resolver is going to map to the register user UDS. And that's how it's gonna work. That's how we do the connection. All right, so let's save that. All right. Let's go back to the GraphQL. Replace this to that again. There it is. Awesome. So now, there you have it. So you have the register owner. Two terms of owner type. Okay, so I'm gonna close some of these. Wait a moment. Okay. So, put in the new mutation. List the owner.
Comments