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