Skip to content
107 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 | "invites"
11 | "keys"
12 | "tokens"
13 | "integrations"
14 | "github"
15 | "applications"
16 | "two-factor"
17 | "security-log"
18 | "account";
19
20/** Each page's name and what it is for, in the sidebar's order. */
21export const ACCOUNT_SETTINGS: Record<AccountSettingsPage, { title: string; about: string; heading?: string }> = {
22 profile: { title: "Profile", about: "Your picture, and what everyone sees on your profile." },
23 emails: {
24 title: "Emails",
25 about:
26 "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.",
27 },
28 notifications: {
29 title: "Notifications",
30 about: "What you are also emailed for, and how you watch repositories. Everything comes to your inbox either way.",
31 },
32 // The invite to g1t, not a workspace's invitation (lib/invites.ts, G1T_INVITES).
33 invites: {
34 title: "Invites to g1t",
35 heading: "Invite people to g1t",
36 about:
37 "An invite to g1t lets one person make an account. It does not add them to any workspace: their account starts with a workspace of its own.",
38 },
39 keys: { title: "SSH keys", about: "Keys that let git on your computers reach g1t as you." },
40 tokens: {
41 title: "Access tokens",
42 about:
43 "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.",
44 },
45 integrations: {
46 title: "Integrations",
47 heading: "Your integrations",
48 about:
49 "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.",
50 },
51 github: {
52 title: "GitHub",
53 about: "Sign in with your GitHub account, and import or mirror repositories you can reach there.",
54 },
55 applications: {
56 title: "Connected applications",
57 about:
58 "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.",
59 },
60 "two-factor": {
61 title: "Two-factor authentication",
62 about:
63 "A code from an app on your phone as well as your password when you sign in. Workspaces can require it of their members.",
64 },
65 "security-log": {
66 title: "Security log",
67 about:
68 "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.",
69 },
70 account: {
71 title: "Account",
72 about: "Your username, and deleting your account.",
73 },
74};
75
76/** Where the first page is: `/settings` goes there. */
77export const FIRST_SETTINGS_PAGE = "/settings/profile";
78
79/**
80 * The sections of the old single settings page, by their `#anchor`, and
81 * the page each now has. Links like `g1t.sh/settings#emails` in old email
82 * and bookmarks still land in the right place.
83 */
84const OLD_ANCHORS: Record<string, AccountSettingsPage> = {
85 picture: "profile",
86 profile: "profile",
87 emails: "emails",
88 github: "github",
89 invites: "invites",
90 "ssh-keys": "keys",
91 tokens: "tokens",
92 applications: "applications",
93 "security-log": "security-log",
94};
95
96/** The page an old `#anchor` of the settings page now lives at, if it was one. */
97export function settingsPathForHash(hash: string): string | null {
98 const page = OLD_ANCHORS[hash.replace(/^#/, "")];
99 return page ? `/settings/${page}` : null;
100}
101
102/** 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. */
103export function accountSettingsPage(pathname: string): AccountSettingsPage | null {
104 const match = /^\/settings\/([^/]+)(?:\/.*)?$/.exec(pathname);
105 const page = match?.[1];
106 return page && page in ACCOUNT_SETTINGS ? (page as AccountSettingsPage) : null;
107}