Skip to content
98 linesCodeBlameRaw
1/**
2 * Your own settings: one page for each part, at `/settings/<page>`, so the
3 * docs, emails and messages can link to exactly the one they mean.
4 */
5
6export type AccountSettingsPage =
7 | "profile"
8 | "emails"
9 | "notifications"
10 | "keys"
11 | "tokens"
12 | "integrations"
13 | "github"
14 | "applications"
15 | "two-factor"
16 | "security-log"
17 | "account";
18
19/** Each page's name and what it is for, in the sidebar's order. */
20export const ACCOUNT_SETTINGS: Record<AccountSettingsPage, { title: string; about: string; heading?: string }> = {
21 profile: { title: "Profile", about: "Your picture, and what everyone sees on your profile." },
22 emails: {
23 title: "Emails",
24 about:
25 "Your primary address gets account mail and password resets. Any confirmed address signs you in and can reset your password, and commits that carry it are shown as yours.",
26 },
27 notifications: {
28 title: "Notifications",
29 about: "What you are also emailed for, and how you watch repositories. Everything comes to your notifications either way.",
30 },
31 keys: { title: "SSH keys", about: "Keys that let git on your computers reach g1t as you." },
32 tokens: {
33 title: "Access tokens",
34 about:
35 "Use a token as the password when git asks for one over HTTPS, and to authenticate agents and the API. A token here acts as you.",
36 },
37 integrations: {
38 title: "Integrations",
39 heading: "Your integrations",
40 about:
41 "Your own accounts, connected just for you and working in every workspace you belong to, such as your calendar setting your status. Tools the whole team shares are a workspace's.",
42 },
43 github: {
44 title: "GitHub",
45 about: "Sign in with your GitHub account, and import repositories you can reach there.",
46 },
47 applications: {
48 title: "Connected applications",
49 about:
50 "Applications you signed in to through your browser, such as an agent connected to the g1t MCP server. Signing one out ends its access at once.",
51 },
52 "two-factor": {
53 title: "Two-factor authentication",
54 about:
55 "A code from an app on your phone as well as your password when you sign in. Workspaces can require it of their members.",
56 },
57 "security-log": {
58 title: "Security log",
59 about:
60 "Changes to your addresses, password, two-factor authentication, keys, tokens and applications, by you or by g1t staff. If you do not recognise one, reset your password.",
61 },
62 account: {
63 title: "Account",
64 about: "Your username, how g1t looks to you, and deleting your account.",
65 },
66};
67
68/** Where the first page is: `/settings` goes there. */
69export const FIRST_SETTINGS_PAGE = "/settings/profile";
70
71/**
72 * The sections of the old single settings page, by their `#anchor`, and
73 * the page each now has. Links like `g1t.sh/settings#emails` in old email
74 * and bookmarks still land in the right place.
75 */
76const OLD_ANCHORS: Record<string, AccountSettingsPage> = {
77 picture: "profile",
78 profile: "profile",
79 emails: "emails",
80 github: "github",
81 "ssh-keys": "keys",
82 tokens: "tokens",
83 applications: "applications",
84 "security-log": "security-log",
85};
86
87/** The page an old `#anchor` of the settings page now lives at, if it was one. */
88export function settingsPathForHash(hash: string): string | null {
89 const page = OLD_ANCHORS[hash.replace(/^#/, "")];
90 return page ? `/settings/${page}` : null;
91}
92
93/** Which settings page a path is, or null when it is none. A page within one (a token under Access tokens) is that page's. */
94export function accountSettingsPage(pathname: string): AccountSettingsPage | null {
95 const match = /^\/settings\/([^/]+)(?:\/.*)?$/.exec(pathname);
96 const page = match?.[1];
97 return page && page in ACCOUNT_SETTINGS ? (page as AccountSettingsPage) : null;
98}