Skip to content
94 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 | "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 }> = {
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 inbox either way.",
30 },
31 invites: { title: "Invites", about: "Bring people to g1t, and see which invites were used." },
32 keys: { title: "SSH keys", about: "Keys that let git on your computers reach g1t as you." },
33 tokens: {
34 title: "Access tokens",
35 about:
36 "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.",
37 },
38 github: {
39 title: "GitHub",
40 about: "Sign in with your GitHub account, and import or mirror repositories you can reach there.",
41 },
42 applications: {
43 title: "Connected applications",
44 about:
45 "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.",
46 },
47 "two-factor": {
48 title: "Two-factor authentication",
49 about:
50 "A code from an app on your phone as well as your password when you sign in. Workspaces can require it of their members.",
51 },
52 "security-log": {
53 title: "Security log",
54 about:
55 "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.",
56 },
57 account: {
58 title: "Account",
59 about: "Your username, and deleting your account.",
60 },
61};
62
63/** Where the first page is: `/settings` goes there. */
64export const FIRST_SETTINGS_PAGE = "/settings/profile";
65
66/**
67 * The sections of the old single settings page, by their `#anchor`, and
68 * the page each now has. Links like `g1t.sh/settings#emails` in old email
69 * and bookmarks still land in the right place.
70 */
71const OLD_ANCHORS: Record<string, AccountSettingsPage> = {
72 picture: "profile",
73 profile: "profile",
74 emails: "emails",
75 github: "github",
76 invites: "invites",
77 "ssh-keys": "keys",
78 tokens: "tokens",
79 applications: "applications",
80 "security-log": "security-log",
81};
82
83/** The page an old `#anchor` of the settings page now lives at, if it was one. */
84export function settingsPathForHash(hash: string): string | null {
85 const page = OLD_ANCHORS[hash.replace(/^#/, "")];
86 return page ? `/settings/${page}` : null;
87}
88
89/** Which settings page a path is, or null when it is none. */
90export function accountSettingsPage(pathname: string): AccountSettingsPage | null {
91 const match = /^\/settings\/([^/]+)\/?$/.exec(pathname);
92 const page = match?.[1];
93 return page && page in ACCOUNT_SETTINGS ? (page as AccountSettingsPage) : null;
94}