0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks 🙏 with a little modification of your query I got my result. I tried Let before but I used it not correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.