Verify Password Reset Token

Determines if the given token in the URL is correct, unexpired, and unused.

Verify a password reset token before allowing the user to enter a new password. Send the token in the URL path to GET /reset/{token}. An unknown token returns 404 Not Found.

Password reset tokens expire after 14 days. If a token has expired, the endpoint returns a 404 status with an ["expired"] response body. If a token has already been used to reset a password, the endpoint returns a 404 status with an ["already used"] response body. This distinction allows the client to display appropriate messaging — for example, offering to send a fresh reset link when a token has expired.

Verify a token with Node.js

  1. Install Node.js 18 or later to use its built-in fetch function.
  2. Set the STAX_API_KEY environment variable to your API key and STAX_RESET_TOKEN to the token from the password reset URL. Keep both values private; do not commit them to source control. The endpoint specification requires bearer authentication.
  3. Save the following code as verify-reset-token.mjs, then run node verify-reset-token.mjs.

The required token path parameter is a string with no default. Tokens expire after 14 days and cannot be reused after a password reset.

const apiKey = process.env.STAX_API_KEY;
// Use the token from the password reset URL, not a Dashboard record ID.
const token = process.env.STAX_RESET_TOKEN;

async function verifyResetToken() {
  if (!apiKey || !token) {
    throw new Error('Set STAX_API_KEY and STAX_RESET_TOKEN before running this script.');
  }

  const response = await fetch(
    `https://apiprod.fattlabs.com/reset/${encodeURIComponent(token)}`,
    {
      headers: {
        Authorization: `Bearer ${apiKey}`,
        Accept: 'application/json',
      },
    },
  );
  const body = await response.text();
  let data;
  try {
    data = JSON.parse(body);
  } catch {
    // A missing token can return a non-JSON Not Found response.
    data = null;
  }

  if (response.status === 200) {
    if (!data || typeof data !== 'object' || Array.isArray(data) || data.token !== token) {
      throw new Error('Unexpected success response. Do not allow a password change.');
    }
    console.log('Token is valid. You can prompt the user for a new password.');
  } else if (response.status === 404) {
    if (Array.isArray(data) && data.includes('expired')) {
      console.error('Token expired. Offer the user a fresh password reset link.');
    } else if (Array.isArray(data) && data.includes('already used')) {
      console.error('Token already used. Ask the user to start a new password reset.');
    } else {
      console.error('Token not found. Do not allow a password change.');
    }
    process.exitCode = 1;
  } else if (response.status === 422) {
    console.error('Token validation failed. Check the token copied from the password reset URL.');
    process.exitCode = 1;
  } else {
    throw new Error(`Verification failed with HTTP ${response.status}. Do not allow a password change.`);
  }
}

verifyResetToken().catch((error) => {
  console.error(`Unable to verify token: ${error.message}`);
  process.exitCode = 1;
});

A valid token produces this console output:

Token is valid. You can prompt the user for a new password.

Expired, used, unknown, or invalid tokens produce the corresponding error message and a nonzero exit code. If the request fails or the response is unexpected, do not allow a password change. For 422, check that you copied the token exactly from the password reset URL; for 404, use the response distinctions below to decide whether to offer a new reset link. This request verifies the token; it does not change the password.

Response Structure

CodeResponseReason
200SuccessThe token is valid and has not expired.
404["expired"]The token has exceeded the 14-day expiry window.
404["already used"]The token has already been used to reset a password.
404Not FoundThe token does not exist.
Path Params
string
required
Responses

Language
Credentials
Bearer
JWT
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json