Sign reviewers in from your own login | CommentKit docs
Skip to content
All docs pages

Sign reviewers in from your own login

Let the people signed in to your website comment without a second sign-in. Your server makes a short-lived token for the signed-in user, and the page passes it to the widget.

Last updated 12 November 2026

What it does and when to use it

Use it when your website has its own login, for example a client portal or a web app your clients already sign in to. Without it, a client opens a client link or signs in with a 6-digit code from their email. With it, the widget signs them in as the person your website says they are, and shows for them on your live site too.

It does not work on localhost: try it on an address on your website's list.

Turn it on

  1. In CommentKit, open your website, then Settings → For developers, under Sign in from your website, choose Make identity secret. A workspace owner or admin can do this.
  2. Copy the secret. It starts with ck_identity_ and is shown once.
  3. Put it on your server as the environment variable COMMENTKIT_IDENTITY_SECRET. Never put it in the page or in your repository.

Make the token on your server

The token is an HS256 JWT. These need no library; any JWT library works too (for example jsonwebtoken or firebase/php-jwt with HS256).

Node
// On your server (Node 16+). Keep COMMENTKIT_IDENTITY_SECRET out of the page.
import { createHmac, randomUUID } from 'node:crypto';

export function commentKitIdentity(user) {
    const part = (value) => Buffer.from(JSON.stringify(value)).toString('base64url');
    const now = Math.floor(Date.now() / 1000);
    const body = part({ alg: 'HS256', typ: 'JWT' }) + '.' + part({
        sub: String(user.id), // your stable user id
        email: user.email,
        name: user.name,
        aud: 'pk_live_your_key',
        iat: now,
        exp: now + 300, // at most 10 minutes
        jti: randomUUID(), // optional: each token works once
    });
    const signature = createHmac('sha256', process.env.COMMENTKIT_IDENTITY_SECRET).update(body).digest('base64url');

    return body + '.' + signature;
}
PHP
<?php
// On your server. Keep COMMENTKIT_IDENTITY_SECRET out of the page.
function commentkit_identity(array $user): string
{
    $part = fn ($value) => rtrim(strtr(base64_encode(json_encode($value)), '+/', '-_'), '=');
    $now = time();
    $body = $part(['alg' => 'HS256', 'typ' => 'JWT']).'.'.$part([
        'sub' => (string) $user['id'], // your stable user id
        'email' => $user['email'],
        'name' => $user['name'],
        'aud' => 'pk_live_your_key',
        'iat' => $now,
        'exp' => $now + 300, // at most 10 minutes
        'jti' => bin2hex(random_bytes(16)), // optional: each token works once
    ]);
    $signature = hash_hmac('sha256', $body, getenv('COMMENTKIT_IDENTITY_SECRET'), true);

    return $body.'.'.rtrim(strtr(base64_encode($signature), '+/', '-_'), '=');
}

Serve it to the signed-in user only, for example from /commentkit-token, which answers with the token as plain text.

Give the token to the widget

A function is best: the widget calls it again whenever the CommentKit session ends.

npm
import { init } from "@commentkit/comment-kit";

const kit = init({
  project: "pk_live_your_key",
  identity: () => fetch("/commentkit-token").then((r) => r.text()),
});

With the script tag, set window.CommentKit before the tag:

Script tag
<script>
  window.CommentKit = { identity: () => fetch("/commentkit-token").then((r) => r.text()) };
</script>
<script src="https://commentkit.dev/cdn/v1/loader.js" data-project="pk_live_your_key" defer></script>

Later, for example right after someone logs in, pass a new token: kit.identify(token), window.CommentKit.identify(token) or document.querySelector("comment-kit").identify(token). In the React, Vue and Svelte helpers, a new identity token signs that person in without a restart. identify() resolves false when the token is refused; it never throws.

Tokens never go in attributes or addresses. The widget never stores or logs them.

Token rules

What the token must contain
PartRule
Headeralg is HS256, signed with your identity secret. No other algorithm, and no crit.
subRequired. Your stable user id, as text, up to 255 characters. It must not change for that person.
emailRequired. A valid email address.
nameOptional. Shown with their comments.
audRequired. Your website key, for example pk_live_your_key.
iat, expRequired, in seconds since 1970. exp is at most 10 minutes after iat. Up to 30 seconds of clock difference are allowed.
jtiOptional. With a jti, the token works once. Make a new one for each page load.
SizeAt most 4096 bytes.

What the reviewer can do

  • They are always a client of this website in CommentKit, never a member of your team, even if their email belongs to one. Your website vouches for its own users, not for CommentKit accounts.
  • They can comment, reply and approve pages, like any client.
  • A CommentKit team member already signed in on that browser stays signed in as themselves.
  • Someone who joined earlier with a client link or an email code, with the same email, is the same person: their comments stay theirs.
  • A client your team removed stays removed (guest_removed).

Sign out with your site

When your site logs someone out, sign them out of CommentKit too. With the npm package, call signOut() on a handle: it ends the CommentKit session and removes that person's unsent drafts on this device. With the React, Vue or Svelte helper or the custom element, init() with the same key gives you a handle onto the same widget:

On logout
import { init } from "@commentkit/comment-kit";

const kit = init({ project: "pk_live_your_key" });
await kit.signOut();
kit.destroy(); // releases this handle only; the widget stays

The script tag's window.CommentKit has no signOut() today. There, the person stays signed in to CommentKit on that browser until they sign out in the widget's Settings, or until the next user's token signs that user in instead.

Replace or turn off the secret

  • Make new secret (in the same place): the old secret keeps working for 24 hours, so you can update your server without signing anyone out.
  • Turn off, if the secret leaked: both secrets stop working at once, and everyone your website signed in is signed out. They can still sign in with an email code. Then make a new secret and put it on your server.

When sign-in fails

identify() resolves false, the error event fires with the code, the console says what to fix when the setup is wrong, and the normal sign-in stays available.

Sign-in errors
CodeWhat happenedWhat to do
identity_not_set_upThe website has no identity secret yet.Make the identity secret (see Turn it on).
identity_invalidThe signature, algorithm, audience, claims or size is wrong. The console names the problem.Check the token against the rules above. aud must be this website key.
identity_expiredThe token is past its exp.Make a new token for each page load (they last at most 10 minutes), or pass a function as identity. Check your server's clock.
identity_replayedA token with this jti was used already.Make a new token, with a new jti, for every sign-in.
identity_conflictAnother user of your site (another sub) already uses this email with CommentKit.Send each user's own stable id as sub. If a user's id changed on your side, ask CommentKit support to move them.
origin_not_allowedThe page's address is not on your website's list, or it is localhost.Add the address in Settings → Install, under Addresses.
guest_removedYour team removed this person from the website.Add them again from the website’s Client links, Restore.