Skip to content

g1t/apps/web/app/lib/account-settings.ts

83 lines3,086 bytesCodeBlame
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 | "security-log";
16
17/** Each page's name and what it is for, in the sidebar's order. */
18export const ACCOUNT_SETTINGS: Record<AccountSettingsPage, { title: string; about: string }> = {
19 profile: { title: "Profile", about: "Your picture, and what everyone sees on your profile." },
20 emails: {
21 title: "Emails",
22 about:
23 "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.",
24 },
25 notifications: {
26 title: "Notifications",
27 about: "What you are also emailed for, and how you watch repositories. Everything comes to your inbox either way.",
28 },
29 invites: { title: "Invites", about: "Bring people to g1t, and see which invites were used." },
30 keys: { title: "SSH keys", about: "Keys that let git on your computers reach g1t as you." },
31 tokens: {
32 title: "Access tokens",
33 about:
34 "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.",
35 },
36 github: {
37 title: "GitHub",
38 about: "Sign in with your GitHub account, and import or mirror repositories you can reach there.",
39 },
40 applications: {
41 title: "Connected applications",
42 about:
43 "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.",
44 },
45 "security-log": {
46 title: "Security log",
47 about:
48 "Changes to your addresses and password, by you or by g1t staff. If you do not recognise one, reset your password.",
49 },
50};
51
52/** Where the first page is: `/settings` goes there. */
53export const FIRST_SETTINGS_PAGE = "/settings/profile";
54
55/**
56 * The sections of the old single settings page, by their `#anchor`, and
57 * the page each now has. Links like `g1t.sh/settings#emails` in old email
58 * and bookmarks still land in the right place.
59 */
60const OLD_ANCHORS: Record<string, AccountSettingsPage> = {
61 picture: "profile",
62 profile: "profile",
63 emails: "emails",
64 github: "github",
65 invites: "invites",
66 "ssh-keys": "keys",
67 tokens: "tokens",
68 applications: "applications",
69 "security-log": "security-log",
70};
71
72/** The page an old `#anchor` of the settings page now lives at, if it was one. */
73export function settingsPathForHash(hash: string): string | null {
74 const page = OLD_ANCHORS[hash.replace(/^#/, "")];
75 return page ? `/settings/${page}` : null;
76}
77
78/** Which settings page a path is, or null when it is none. */
79export function accountSettingsPage(pathname: string): AccountSettingsPage | null {
80 const match = /^\/settings\/([^/]+)\/?$/.exec(pathname);
81 const page = match?.[1];
82 return page && page in ACCOUNT_SETTINGS ? (page as AccountSettingsPage) : null;
83}