FaunaDB Functions query data after Login

71 views Asked by At

I need some help with a FaunaDB function.

I have the following register function to register a User:

Query(
  Lambda(
    ["email", "username", "password"],
    Create(Collection("User"), {
      credentials: { password: Var("password") },
      data: { email: Var("email"), username: Var("username") }
    })
  )
)

It works fine and returns the following output:

{
  ref: Ref(Ref("tokens"), "220428023135601160"),
  ts: 1603695853275000,
  ttl: Time("2020-10-26T10:04:12.646314Z"),
  instance: Ref(Collection("User"), "220412125733585420"),
  secret: "SECRET_STRING"
}

I want to change the function so that it returns the User Data according to the Ref of the instance variable Get(Var("instance")) and the secret string. So that it looks similar to this:

{
  secret: "SECRET_STRING",
  user: {
          ... //user data
        }
}

I am tried to apply several functions but did not get it to work...

1

There are 1 answers

1
Luigi Servini On BEST ANSWER

Something like that might work for you?

Let(
  {
    email: "[email protected]",
    username: "user1",
    password: "mypassword",
    document: Create(Collection("User"), {credentials: { password: Var("password") },data: { email: Var("email"), username: Var("username") }})
  },
  {
    secret: Var('password'),
    ref: Select(['ref'],Var('document')),
    data:Select(['data'],Var('document'))
  }
)

Luigi