-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
32 lines (25 loc) · 829 Bytes
/
Copy pathauth.ts
File metadata and controls
32 lines (25 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { GLUE_API_SERVER } from "./common.ts";
import { kv } from "./db.ts";
export const AUTH_TOKEN_KEY = "authToken";
export async function setAuthToken(authToken: string) {
await kv.set([AUTH_TOKEN_KEY, GLUE_API_SERVER], authToken);
}
export async function getAuthToken() {
return (await kv.get<string>([AUTH_TOKEN_KEY, GLUE_API_SERVER])).value;
}
export async function clearAuthToken() {
await kv.delete([AUTH_TOKEN_KEY, GLUE_API_SERVER]);
}
export async function checkForAuthCredsOtherwiseExit() {
const authToken = await getAuthToken();
if (!authToken) {
exitBecauseNotLoggedIn();
}
}
export function exitBecauseNotLoggedIn(): never {
console.error("You are not logged in. Try `glue login`.");
Deno.exit(1);
}
export async function isLoggedIn() {
return (await getAuthToken()) !== undefined;
}