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