Skip to content

Commit

Permalink
Read token from environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
2can committed Oct 27, 2023
1 parent 1b4bf1e commit fadf1f5
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,33 @@ export const useToken = async ({ token }: Options) => {
const config = await Config.get();
const { token: configToken } = config;

if (process.env.SALEOR_CLI_TOKEN) {
debug('token read from env');
opts = { ...opts, token: `TOKEN ${process.env.SALEOR_CLI_TOKEN}` };
return opts;
}

if (configToken) {
debug('token read from file');
opts = { ...opts, token: configToken };
} else {
console.error(chalk.red('\nYou are not logged in\n'));
console.error(
chalk(
'If you have an account - login using',
chalk.bold.green('saleor login'),
),
);
console.error(
chalk(
'If you don\'t have an account - register using',
chalk.bold.green('saleor register'),
),
);

process.exit(1);
return opts;
}

console.error(chalk.red('\nYou are not logged in\n'));
console.error(
chalk(
'If you have an account - login using',
chalk.bold.green('saleor login'),
),
);
console.error(
chalk(
'If you don\'t have an account - register using',
chalk.bold.green('saleor register'),
),
);

process.exit(1);
}

return opts;
Expand Down

0 comments on commit fadf1f5

Please sign in to comment.