diff --git a/.changeset/unlucky-queens-divide.md b/.changeset/unlucky-queens-divide.md new file mode 100644 index 000000000..8935b8f06 --- /dev/null +++ b/.changeset/unlucky-queens-divide.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +`graph auth`: fix bug with setting deploy key diff --git a/packages/cli/src/commands/auth.ts b/packages/cli/src/commands/auth.ts index 9e04cc63b..a09a830ca 100644 --- a/packages/cli/src/commands/auth.ts +++ b/packages/cli/src/commands/auth.ts @@ -1,5 +1,5 @@ import { print, prompt } from 'gluegun'; -import { Args, Command, Flags, ux } from '@oclif/core'; +import { Args, Command, Flags } from '@oclif/core'; import { saveDeployKey } from '../command-helpers/auth.js'; import { chooseNodeUrl } from '../command-helpers/node.js'; @@ -16,6 +16,11 @@ export default class AuthCommand extends Command { }), }; + private validateStudioDeployKey(value: string | undefined): boolean { + if (!value) return false; + return /^[0-9a-fA-F]{32}$/.test(value); + } + async run() { const { args: { 'deploy-key': initialDeployKey }, @@ -25,15 +30,14 @@ export default class AuthCommand extends Command { const { deployKey } = await prompt.ask<{ deployKey: string }>([ { - type: 'invisible', + type: 'input', name: 'deployKey', - message: () => 'What is the deploy key?', - initial: initialDeployKey, + message: () => 'What is your Subgraph Studio deploy key?', required: true, + initial: initialDeployKey, + skip: this.validateStudioDeployKey(initialDeployKey), validate: value => - value.length > 200 - ? ux.error('✖ Deploy key must not exceed 200 characters', { exit: 1 }) - : value, + this.validateStudioDeployKey(value) || `Invalid Subgraph Studio deploy key: ${value}`, }, ]); @@ -41,7 +45,7 @@ export default class AuthCommand extends Command { await saveDeployKey(node!, deployKey); print.success(`Deploy key set for ${node}`); } catch (e) { - this.error(e, { exit: 1 }); + this.error(`Failed to set deploy key: ${e.message}`, { exit: 1 }); } } }