Obtain document id

I log in via the UI app using the following function, which currently gives me a token:

{
  name: "login_user",
  role: Role("login"),
  body: Query(
    Lambda(
      ["username", "password"],
      Let(
        {
          match: Match(Index("unique_User_username"), Var("username")),
          user: If(Exists(Var("match")), Get(Var("match")), "false"),
          login: Login(Select("ref", Var("user")), {
            password: Var("password")
          })
        },
        Select("secret", Var("login"))
      )
    )
  )
}

How can I update this function to also send the document id from the ‘Users’ collection back in the response? thanks …

1 Like

Hi @FreeRoss,

Something like that:

 {
  name: "login_user",
  role: Role("login"),
  body: Query(
    Lambda(
      ["username", "password"],
      Let(
        {
          match: Match(Index("unique_User_username"), Var("username")),
          user: If(Exists(Var("match")), Get(Var("match")), "false"),
          login: Login(Select("ref", Var("user")), {
            password: Var("password")
          })
        },
        {
          user: Var('user'),
          password: Select("secret", Var("login"))
        }
      )
    )
  )
}

Luigi