Skip to content

Commit c386a7d

Browse files
committed
Reuse readAuthToken in checkIsAuthenticated
1 parent ce63599 commit c386a7d

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/utils/authenticate.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,6 @@ export async function saveAuthToken(
124124
}
125125
}
126126

127-
/**
128-
* Checks if the user is authenticated by validating the stored auth token.
129-
*
130-
* License is validated separately
131-
*
132-
* @returns boolean indicating if the authentication is valid
133-
*/
134-
export async function checkIsAuthenticated() {
135-
try {
136-
const authJson = await fs.readFile(LOCALSTACK_AUTH_FILENAME, "utf-8");
137-
const authObject = JSON.parse(authJson) as unknown;
138-
if (!isAuthTokenPresent(authObject)) {
139-
return false;
140-
}
141-
const authToken = authObject[AUTH_TOKEN_KEY];
142-
if (typeof authToken !== "string") {
143-
return false;
144-
}
145-
return true;
146-
} catch {
147-
return false;
148-
}
149-
}
150-
151127
function isAuthTokenPresent(authObject: unknown) {
152128
return (
153129
typeof authObject === "object" &&
@@ -173,3 +149,14 @@ export async function readAuthToken(): Promise<string> {
173149
return "";
174150
}
175151
}
152+
153+
/**
154+
* Checks if the user is authenticated by validating the stored auth token.
155+
*
156+
* License is validated separately
157+
*
158+
* @returns boolean indicating if the authentication is valid
159+
*/
160+
export async function checkIsAuthenticated() {
161+
return (await readAuthToken()) !== "";
162+
}

0 commit comments

Comments
 (0)