import { verifyKey } from "@unkey/api";
const { result, error } = await verifyKey({ key: "key_123", apiId: "api_123" });
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
if (!result.valid) {
// do not grant access
return;
}
// process request
console.log(result);
{
"result": {
"keyId": "key_1234",
"valid": true,
"name": "Customer X",
"ownerId": "user_123",
"meta": {
"roles": [
"admin",
"user"
],
"stripeCustomerId": "cus_1234"
},
"expires": 123,
"ratelimit": {
"limit": 10,
"remaining": 9,
"reset": 3600000
},
"remaining": 1000,
"code": "VALID",
"enabled": true,
"permissions": [
"dns.record.update",
"dns.record.delete"
],
"environment": "test",
"identity": {
"id": "<string>",
"externalId": "<string>",
"meta": {}
}
}
}
Verify a key
import { verifyKey } from "@unkey/api";
const { result, error } = await verifyKey({ key: "key_123", apiId: "api_123" });
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
if (!result.valid) {
// do not grant access
return;
}
// process request
console.log(result);
{
"result": {
"keyId": "key_1234",
"valid": true,
"name": "Customer X",
"ownerId": "user_123",
"meta": {
"roles": [
"admin",
"user"
],
"stripeCustomerId": "cus_1234"
},
"expires": 123,
"ratelimit": {
"limit": 10,
"remaining": 9,
"reset": 3600000
},
"remaining": 1000,
"code": "VALID",
"enabled": true,
"permissions": [
"dns.record.update",
"dns.record.delete"
],
"environment": "test",
"identity": {
"id": "<string>",
"externalId": "<string>",
"meta": {}
}
}
}
import { verifyKey } from "@unkey/api";
const { result, error } = await verifyKey({ key: "key_123", apiId: "api_123" });
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
if (!result.valid) {
// do not grant access
return;
}
// process request
console.log(result);
{
"result": {
"keyId": "key_1234",
"valid": true,
"name": "Customer X",
"ownerId": "user_123",
"meta": {
"roles": [
"admin",
"user"
],
"stripeCustomerId": "cus_1234"
},
"expires": 123,
"ratelimit": {
"limit": 10,
"remaining": 9,
"reset": 3600000
},
"remaining": 1000,
"code": "VALID",
"enabled": true,
"permissions": [
"dns.record.update",
"dns.record.delete"
],
"environment": "test",
"identity": {
"id": "<string>",
"externalId": "<string>",
"meta": {}
}
}
}
Hide properties
Hide properties
false
you
should not grant access to whatever the user is requestingownerId
on this key it is returned here. You can use this
to clearly authenticate a user in your system.meta
data you have set when creating the key.Example:{
"billingTier": "PRO",
"trialEnds": "2023-06-16T17:16:37.161Z"
}
remaining
count.NOT_FOUND
- The key does not existFORBIDDEN
- You are not allowed to verify this key. For example because of additional security
checks like IP whitelists
USAGE_EXCEEDED
- The key has been used up and is no longer validRATE_LIMITED
- The verification has been blocked due to ratelimitingDISABLED
- The key is disabledEXPIRED
- The key has expiredWas this page helpful?