Generate a UUID
Problem
You want to generate a random and unique id for use in your application.
Solution
Use the built-in $crypto.randomUUID()
function to receive a string of a random UUID (opens in a new tab) v4.
For example in a TypeScript client function:
Code example
const myUUID = $crypto.randomUUID()
return myUUID // => f0914ce4-0701-4c6e-b704-3b96b3654eb7
Discussion
- The
$crypto
library is available on both TypeScript Client and TypeScript Server resource functions.