@base44-preview/cli 0.0.54-pr.538.7e2f1d6 → 0.0.54-pr.538.d4fa204

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -235165,27 +235165,28 @@ function decodeJwtClaims(token) {
235165
235165
  return null;
235166
235166
  }
235167
235167
  }
235168
- function readEnvAuth() {
235168
+ async function seedAuthFromEnv() {
235169
235169
  const accessToken = process.env.BASE44_ACCESS_TOKEN;
235170
235170
  if (!accessToken) {
235171
- return null;
235171
+ return false;
235172
235172
  }
235173
+ const refreshToken = process.env.BASE44_REFRESH_TOKEN;
235173
235174
  const claims = decodeJwtClaims(accessToken);
235174
- const sub = typeof claims?.sub === "string" ? claims.sub : "";
235175
- const exp = typeof claims?.exp === "number" ? claims.exp : null;
235176
- return {
235175
+ const sub = typeof claims?.sub === "string" ? claims.sub : undefined;
235176
+ const exp = typeof claims?.exp === "number" ? claims.exp : undefined;
235177
+ if (!refreshToken || !sub || !exp) {
235178
+ return false;
235179
+ }
235180
+ await writeAuth({
235177
235181
  accessToken,
235178
- refreshToken: process.env.BASE44_REFRESH_TOKEN ?? "",
235179
- expiresAt: exp !== null ? exp * 1000 : Number.POSITIVE_INFINITY,
235182
+ refreshToken,
235183
+ expiresAt: exp * 1000,
235180
235184
  email: sub,
235181
- name: ""
235182
- };
235185
+ name: sub
235186
+ });
235187
+ return true;
235183
235188
  }
235184
235189
  async function readAuth() {
235185
- const envAuth = readEnvAuth();
235186
- if (envAuth) {
235187
- return envAuth;
235188
- }
235189
235190
  try {
235190
235191
  const authData = await readJsonFile(getAuthFilePath());
235191
235192
  const result = AuthDataSchema.safeParse(authData);
@@ -235222,9 +235223,6 @@ function isTokenExpired(auth) {
235222
235223
  return Date.now() >= auth.expiresAt - TOKEN_REFRESH_BUFFER_MS;
235223
235224
  }
235224
235225
  async function refreshAndSaveTokens() {
235225
- if (readEnvAuth()) {
235226
- return null;
235227
- }
235228
235226
  if (refreshPromise) {
235229
235227
  return refreshPromise;
235230
235228
  }
@@ -244424,6 +244422,7 @@ async function login({
244424
244422
 
244425
244423
  // src/cli/utils/command/middleware.ts
244426
244424
  async function ensureAuth(ctx) {
244425
+ await seedAuthFromEnv();
244427
244426
  const loggedIn = await isLoggedIn();
244428
244427
  if (!loggedIn) {
244429
244428
  ctx.log.info("You need to login first to continue.");
@@ -261823,4 +261822,4 @@ export {
261823
261822
  CLIExitError
261824
261823
  };
261825
261824
 
261826
- //# debugId=B453E5669D23DDA064756E2164756E21
261825
+ //# debugId=C760C3B8B75787D664756E2164756E21