Skip to content

Commit e69abeb

Browse files
committed
Reuse readAuthToken in checkIsAuthenticated
1 parent c1b44b4 commit e69abeb

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
@@ -112,30 +112,6 @@ export async function saveAuthToken(
112112
}
113113
}
114114

115-
/**
116-
* Checks if the user is authenticated by validating the stored auth token.
117-
*
118-
* License is validated separately
119-
*
120-
* @returns boolean indicating if the authentication is valid
121-
*/
122-
export async function checkIsAuthenticated() {
123-
try {
124-
const authJson = await fs.readFile(LOCALSTACK_AUTH_FILENAME, "utf-8");
125-
const authObject = JSON.parse(authJson) as unknown;
126-
if (!isAuthTokenPresent(authObject)) {
127-
return false;
128-
}
129-
const authToken = authObject[AUTH_TOKEN_KEY];
130-
if (typeof authToken !== "string") {
131-
return false;
132-
}
133-
return true;
134-
} catch {
135-
return false;
136-
}
137-
}
138-
139115
function isAuthTokenPresent(authObject: unknown) {
140116
return (
141117
typeof authObject === "object" &&
@@ -161,3 +137,14 @@ export async function readAuthToken(): Promise<string> {
161137
return "";
162138
}
163139
}
140+
141+
/**
142+
* Checks if the user is authenticated by validating the stored auth token.
143+
*
144+
* License is validated separately
145+
*
146+
* @returns boolean indicating if the authentication is valid
147+
*/
148+
export async function checkIsAuthenticated() {
149+
return (await readAuthToken()) !== "";
150+
}

0 commit comments

Comments
 (0)