Delete a token

Problem

You need to delete a token from the current database.

Solution

Use the function:Delete[] function:

try
{
    Value result = await client.Query(
        Delete(Ref(Tokens(), "1"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "1", collection = RefV(id = "tokens")),ts: LongV(1631740130800000),instance: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),hashed_secret: StringV($2a$05$ido9qqXfQ.KjpZQLfGqYJup/kilkj9Vqka3Yuzx//oPpjsJw69QHO),data: ObjectV(team: StringV(Marketing)))
result, err := client.Query(
	f.Delete(f.Ref(f.Tokens(), "1")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[team:Marketing] hashed_secret:$2a$05$a77WPbm2U.Ms6GSw6oNp5uOZMefME5e.hLQxIhsgh/h2ceKQpxS8W instance:{1 0xc000109a10 0xc000109a10 <nil>} ref:{1 0xc000109860 0xc000109860 <nil>} ts:1631739856660000]
client.query(
  q.Delete(q.Ref(q.Tokens(), '1'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Ref(Tokens(), "1"),
  ts: 1631739422930000,
  instance: Ref(Collection("users"), "1"),
  hashed_secret: '$2a$05$HgbE0YEse2i7.5F4a5MHm.wGDmk4C3kMrP7NJpP40GrO06DgP584q',
  data: { team: 'Marketing' }
}
result = client.query(
  q.delete(q.ref(q.tokens(), "1"))
)
print(result)
{'ref': Ref(id=1, collection=Ref(id=tokens)), 'ts': 1631739701090000, 'instance': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'hashed_secret': '$2a$05$HExlDNKKmJP69pnpzVmf1.nsTDOJ5FbgfwUv9z1CXg./nQBsT70ny', 'data': {'team': 'Marketing'}}
Delete(Ref(Tokens(), '1'))
{
  ref: Ref(Tokens(), "1"),
  ts: 1631738655590000,
  instance: Ref(Collection("users"), "1"),
  hashed_secret: '$2a$05$jr3cTMQcY.mKNNizVlQIZOpIC3wVjvxuse93/FDw9A9JbX9.9lIoy',
  data: { team: 'Marketing' }
}
Query metrics:
  •    bytesIn:   43

  •   bytesOut:  318

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  303

  • writeBytes:  439

  •  queryTime: 15ms

  •    retries:    0

Discussion

Once a key has been deleted, any client still using the key’s secret can no longer execute queries.

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!