Skip to content

Getting Started

Declare the secret in application code and register it with the backend app.

Terminal window
import { backend } from "@layeron/core"
import { secret } from "@layeron/modules"
const app = backend()
const stripeSecret = secret.static({
name: "stripe-secret",
namespace: "billing",
})
app.use(stripeSecret)

Use the Secret product object from a route or product integration.

Terminal window
app.post("/billing/customer", async () => {
const apiKey = await stripeSecret.current().text()
return {
configured: apiKey.length > 0,
}
})

High-level helpers are available for signing and verification:

Terminal window
const sessionKey = secret.random({
name: "session-key",
namespace: "auth",
})
app.use(sessionKey)
app.post("/session", async () => {
return {
token: await sessionKey.signJwt({ sub: "user_123" }, { expiresIn: "30m" }),
}
})

For direct Cloudflare deploys, write the value into the user’s Cloudflare Secrets Store:

Terminal window
layer secret set STRIPE_SECRET --value-env STRIPE_SECRET

The command uses Cloudflare credentials from layer login.

  • Values and versioning: Use static, random, generated, and versioned secret values.
  • Cloudflare values: Write deploy values, local CLI values, versioned values, and generated rotations.
  • Rotation: Configure rotation intervals, retention modes, direct deploy behavior, and rotation state.
  • API reference: Review Secret options, value formats, ownership, consume settings, and module methods.