Pubkey validation

Hey there!

I’m building a tool around Uploadcare, where users will be required to use their pubkeys to upload images to Uploadcare. I’d like to validate their pubkeys prior to letting them use the tool. Just to make UX a bit better.

Which way should I use? Is there any pubkey validation method? Currently I found only this solution:

const { info } = require('@uploadcare/upload-client');

(async () => {
  console.log(await isPublicKeyInvalid('invalid key'));
  console.log(await isPublicKeyInvalid('demopublickey'));

async function isPublicKeyInvalid(publicKey) {
  try {
    await info(
      'nothing here',
  } catch (err) {
    const apiError = err.response.error;
    return apiError.statusCode === 403 && apiError.errorCode === 'ProjectPublicKeyInvalidError';
$ node index.js 

Is there a way to make it more bulletproof? May I rely on errorCode there?

Hi @igoradamenko, thanks for the question! There’s no dedicated method for validating API keys, but you can rely on errorCode; your solution should work just fine :+1:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.