Skip to content

Instantly share code, notes, and snippets.

@ryancharris
Created October 5, 2020 16:59
Show Gist options
  • Save ryancharris/ed6dfd96d3a9f64052b22a63fb531de6 to your computer and use it in GitHub Desktop.
Save ryancharris/ed6dfd96d3a9f64052b22a63fb531de6 to your computer and use it in GitHub Desktop.
API v4 demo code
const faunadb = require("faunadb");
const q = faunadb.query;
// Instantiate client
const client = new faunadb.Client({
secret: FAUNA_KEY,
domain: "localhost",
scheme: "http",
port: 8443
});
function createProvider(name) {
return client.query(
q.CreateAccessProvider({
name: name,
issuer: name,
jwks_uri: "https://my-provider-url.auth0.com",
membership: [q.Role("MyCustomRole")]
})
);
}
function getAllProviders() {
return client.query(q.Paginate(q.AccessProviders()));
}
function getProviderById(name) {
return client.query(q.Get(q.AccessProvider(name)));
}
async function main() {
const newProviderName = "good-morning";
const provider = await createProvider(newProviderName);
console.log("provider", provider);
const allProviders = await getAllProviders();
console.log("allProviders", allProviders);
const providerById = await getProviderById(newProviderName);
console.log("providerById", providerById);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment