-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlogout.ts
More file actions
66 lines (60 loc) · 1.7 KB
/
logout.ts
File metadata and controls
66 lines (60 loc) · 1.7 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* sentry auth logout
*
* Clear stored authentication credentials.
*/
import type { SentryContext } from "../../context.js";
import { buildCommand } from "../../lib/command.js";
import {
clearAuth,
getActiveEnvVarName,
isAuthenticated,
isEnvTokenActive,
} from "../../lib/db/auth.js";
import { getDbPath } from "../../lib/db/index.js";
import { AuthError } from "../../lib/errors.js";
import { formatLogoutResult } from "../../lib/formatters/human.js";
import { CommandOutput } from "../../lib/formatters/output.js";
/** Structured result of the logout operation */
export type LogoutResult = {
/** Whether logout actually cleared credentials */
loggedOut: boolean;
/** Informational message when no action was taken */
message?: string;
/** Path where credentials were stored (when loggedOut is true) */
configPath?: string;
};
export const logoutCommand = buildCommand({
auth: false,
docs: {
brief: "Log out of Sentry",
fullDescription:
"Remove stored authentication credentials from the local database.",
},
output: { human: formatLogoutResult },
parameters: {
flags: {},
},
async *func(this: SentryContext) {
if (!isAuthenticated()) {
return yield new CommandOutput({
loggedOut: false,
message: "Not currently authenticated.",
});
}
if (isEnvTokenActive()) {
const envVar = getActiveEnvVarName();
throw new AuthError(
"invalid",
`Authentication is provided via ${envVar} environment variable. ` +
`Unset ${envVar} to log out.`
);
}
const configPath = getDbPath();
await clearAuth();
return yield new CommandOutput({
loggedOut: true,
configPath,
});
},
});