UNPKG

@metacall/deploy

Version:

Tool for deploying into MetaCall FaaS platform.

35 lines (34 loc) 1.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = require("fs/promises"); const config_1 = require("../config"); const utils_1 = require("../utils"); const args_1 = __importDefault(require("./args")); const messages_1 = require("./messages"); const handleValidateToken = async (api) => { const validToken = await api.validate(); if (!validToken) { const token = await api.refresh(); await (0, config_1.save)({ token }); } }; const validateToken = async (api) => { try { await handleValidateToken(api); } catch (err) { if (args_1.default['dev']) { (0, messages_1.info)('Please visit https://github.com/metacall/faas to learn how to set up FaaS locally.'); return (0, messages_1.error)('FaaS is not serving locally.'); } // Removing cache such that user will have to login again. const configFile = (0, config_1.configFilePath)(); (await (0, utils_1.exists)(configFile)) && (await (0, promises_1.unlink)(configFile)); (0, messages_1.info)('Try to login again!'); return (0, messages_1.error)(`Token validation failed, potential causes include:\n\t1) The JWT may be mistranslated (Invalid Signature).\n\t2) JWT might have expired.`); } }; exports.default = validateToken;