TheHackStack Docs Sign in

#Verify Your Review integration

Reviews left through your Review button or link are already Verified. This page is the optional server-side way: the Verify Your Review button lets a customer who is signed in to your app give their TheHackStack review a Verified badge, or write a new review that's verified as soon as it's published.

Two pieces are needed:

  1. A backend route on your site that creates a verification session (server to server, with your API key).
  2. The button, from the SDK.

#1. Backend route

Your route must:

  1. Authenticate the visitor with your own session. Return 401 if they aren't signed in; the SDK then reports not_signed_in.
  2. Call POST /api/v1/verification-sessions with your API key and your id for that customer.
  3. Return { "verification_url": "…", "expires_at": "…" } with Cache-Control: no-store.
  4. Reject requests without JSON and the X-THS-SDK header. The SDK always sends both. Another site can't send them without a CORS preflight, so this blocks CSRF even where your framework's CSRF token isn't sent (the SDK doesn't send framework tokens).

Never read the customer id, email or user id from the request. Take them from your session. Complete, working routes for Node.js, Laravel and Flask follow this pattern:

// Express. requireLogin is your own auth middleware.
app.post('/api/thehackstack/verification-session', requireLogin, express.json(), async (req, res) => {
  if (!req.is('application/json') || !req.get('X-THS-SDK')) return res.status(403).json({ error: 'csrf' }); // CSRF
  const intent = req.body?.intent === 'write' ? 'write' : 'verify';
  const r = await fetch('https://thehackstack.com/api/v1/verification-sessions', {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.THS_API_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ customer: { id: String(req.user.id) }, intent }),
  });
  const data = await r.json();
  if (!r.ok) return res.status(502).json({ error: 'verification_unavailable' }); // log data.error.code, never the URL
  res.set('Cache-Control', 'no-store').json({ verification_url: data.verification_url, expires_at: data.expires_at });
});

#2. Button

<script src="https://thehackstack.com/sdk/v1.2.0/ths-reviews.js"
        integrity="sha384-rSq3igDf1LtE8FQQEWmUsDIdvfJwHKXsykIji4SSHzwGhlGzhpMp6zPhb30s13Rb"
        crossorigin="anonymous"
        data-app-id="ths_app_XXXXXXXXXXXXXXXXXXXXXXXX"
        data-session-endpoint="/api/thehackstack/verification-session" async></script>

<!-- render only for signed-in customers -->
<button data-ths-review-button="verify">Verify your review</button>

#Choosing the intent

Intent Use when Reviewer already reviewed you Reviewer hasn't
verify (default) e.g. a "Thanks for reviewing us!" email or page Confirms the existing review Shown the review form
write Asking for a new review Confirms the existing review (can edit it first) Shown the review form
<button data-ths-review-button="verify">Verify your review</button>
<button data-ths-review-button="verify" data-ths-intent="write">Write a verified review</button>

Each reviewer has one review per product; writing again updates it.

#Show errors to your users

THSReviews.init({
  appId: 'ths_app_XXXXXXXXXXXXXXXXXXXXXXXX',
  sessionEndpoint: '/api/thehackstack/verification-session',
  onError(err) {
    const messages = {
      not_signed_in: 'Please sign in to your account first.',
      network_error: 'Connection problem. Please try again.',
      timeout: 'Connection problem. Please try again.',
      session_expired: 'That took too long. Please try again.',
    };
    showToast(messages[err.code] || 'Verification is unavailable right now.');
  },
});

#What happens next

The browser navigates to https://thehackstack.com/verify#token=…. TheHackStack takes the reviewer through sign-in or sign-up and email confirmation, then to your product's review section. The badge is granted only when the signed-in reviewer confirms. Your API can't grant it on its own.

#Test checklist

  • Signed-out visitor: your endpoint returns 401; the button shows your sign-in message.
  • Signed-in customer with an existing TheHackStack review: they confirm it and the badge appears.
  • New TheHackStack user: they sign up, confirm their email, write a review and the badge appears.
  • Clicking twice quickly creates one session (the button is disabled while busy).
  • Your logs contain the session id (vs_…) but never verification_url.
API and SDK served from https://thehackstack.com. Report security issues privately to the TheHackStack team.