Create a sign-in function
This tutorial builds on the basic login feature by defining a function to log in users.
Typically, applications use email and password
credentials for signing up new users. Each user is identified by their unique
email address so it is important to constrain the People.email field so that
it is unique.
-
In the Fauna Shell, select the Admin Built-in Role.
-
Add a unique constraint to the
Peoplecollectionemailfield:{ name: "People", coll: Collection, ts: Time("2023-07-25T22:03:50.820Z"), constraints: [ { unique: [ "email" ], status: "active" } ] } -
Create a user-defined function that signs up users:
{ name: "Signup", coll: Function, ts: Time("2023-07-25T15:59:03.950Z"), role: "server", body: <<-END (username, email, password) => { let user = People.create({ name: username, email: email }) Credentials.create({ document: user, password: password }) } END }When called from the Shell or an application you provide
username,email, andpasswordparameters. -
The function creates a
Peopledocument that becomes the identity of theCredentialdocument that the function returns. Verify theSignupfunction:{ id: "371240301830864930", coll: Credential, ts: Time("2023-07-25T16:06:31.110Z"), document: People.byId("371240301825622050") }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!