Rhea Key SDK

Developer guide

Add Sign in with Rhea Key

A person approves on their device. Your server checks the result and starts its own session. Rhea never receives a recovery phrase or private key.

The official button shows the Rhea mark and the word Key in red (white on the red theme). See a live sign-in at rheakey.com/demo.

1Register your site

Unlock Rhea Key on rheakey.com/apps and add the exact address your site uses. The button only works on a registered site, and registration is signed by your key. There is no email signup.

Register your site

For local work, register a loopback address. It needs no domain proof:

Redirect address
http://localhost:3000/api/auth/callback/rheakey

The button is allowed on that address's origin (here http://localhost:3000). A public https site also proves it controls the host, with a short token at /.well-known/rheakey or a DNS TXT record on _rheakey. Addresses are matched exactly. No wildcards.

2Add the button and try it

Paste this into a page on http://localhost:3000. The two test attributes let you approve a sign-in before you write any server code:

HTML
<!-- Test only. Works on http://localhost after step 1. -->
<script src="https://rheakey.com/sdk/rhea.js" async></script>
<rhea-button app-name="My App" challenge="client" verify-url="none"></rhea-button>
<script>
  document.addEventListener("rhea-success", (e) => console.log("Approved by", e.detail.address));
  document.addEventListener("rhea-error", (e) => console.warn("Rhea Key:", e.detail.code));
</script>

challenge="client" only works on localhost; the button refuses it anywhere else. Never ship verify-url="none".

3Verify on your server

Add two routes on the same origin, then remove the two test attributes. The button calls them for you:

  • POST /rhea-challenge returns { nonce, issuedAt, expirationTime } and sets an HttpOnly cookie that points at that one challenge.
  • POST /rhea-verify receives { message, signature, address }, checks it against that challenge, starts a new session and answers 2xx. Any other answer shows “This site could not confirm sign-in”.
HTML
<script src="https://rheakey.com/sdk/rhea.js" async></script>
<rhea-button app-name="My App"></rhea-button>
<script>
  // Fires only after your /rhea-verify route answered 2xx.
  document.addEventListener("rhea-success", () => location.reload());
  document.addEventListener("rhea-error", (e) => console.warn("Rhea Key:", e.detail.code));
</script>

The browser event is not enough. Always verify on your server before you create a session. Issue a new session id; never reuse the old one. Every check is listed on RK-1.

Already use an identity library?

Use OpenID Connect instead of the button: register a callback in step 1, then point Auth.js, Auth0, Keycloak or any OIDC client at the issuer https://rheakey.com.

Auth.js / NextAuth
// auth.ts (Auth.js v5). Works today; no Rhea package needed.
// Callback: http://localhost:3000/api/auth/callback/rheakey
import NextAuth from "next-auth";

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [{
    id: "rheakey",
    name: "Rhea Key",
    type: "oidc",
    issuer: "https://rheakey.com",
    clientId: process.env.RHEA_CLIENT_ID,
    clientSecret: process.env.RHEA_CLIENT_SECRET,
    checks: ["pkce", "state", "nonce"],
    client: {
      token_endpoint_auth_method: "client_secret_post",
      id_token_signed_response_alg: "ES256",
    },
  }],
});

Full settings are on OIDC. If something fails, the code is explained on Errors.