// The pages' words (spec/OAUTH-PAGES.md), in one place: the headings, the // accessible names of the fields and buttons, and the alerts. The words of // each scope are in scopes.ts. import type { Answer } from './api'; export const words = { signIn: 'Sign in', identifier: 'Handle or email', password: 'Password', remember: 'Remember this account on this device', back: 'Back', cancel: 'Cancel', checkEmail: 'Check your email', code: 'Code', chooseAccount: 'Choose an account', anotherAccount: 'Another account', allowAccess: 'Allow access', allow: 'Allow', deny: 'Deny', technicalDetails: 'Technical details', terms: 'Terms', privacy: 'Privacy policy', loopbackClient: 'An app on your device', app: 'App', account: 'Account', asksFor: 'What it asks for', somethingWentWrong: 'Something went wrong', errorCode: 'Error: ', signInWithPasskey: 'Sign in with a passkey', or: 'or', addAPasskey: 'Add a passkey', addPasskey: 'Add passkey', passkeyAdded: 'Passkey added', setDetails: 'Details', setRequests: 'The application requests the permissions necessary to perform the following actions on your behalf:', setGrantsNothing: 'Asks for nothing this server grants.', call: 'Call', towards: 'Towards', data: 'Data', actions: ['Create', 'Update', 'Delete'], yes: 'Yes' } as const; export const continueAs = (handle: string) => `Continue as @${handle}`; export const sentCode = (identifier: string) => `We sent a sign-in code to the email address of ${identifier}.`; export const passkeyWillSignIn = (name: string, handle: string) => `This passkey, named ${name}, will sign in to @${handle} on this server.`; export const passkeyCanSignIn = (handle: string) => `@${handle} can now sign in with this passkey. You can close this page.`; export const passkeyExists = (handle: string) => `This device already has a passkey for @${handle}.`; export const alerts = { wrongPassword: 'Wrong handle, email or password.', wrongCode: 'Wrong code. Use the code in the latest email.', ended: 'This sign-in has ended. Go back to the app and start again.', outOfSpace: 'The server is out of space. Try again later.', failed: 'Something went wrong. Try again.', noPasskeyUsed: 'No passkey was used.', otherAccount: 'That passkey is for another account.', passkeyRefused: 'That passkey did not sign in. Try again, or use your password.', noWebAuthn: 'This browser cannot make passkeys.', noPasskeyMade: 'No passkey was made. Try again.', linkEnded: 'This link has ended. Make a new one with pds passkey add.', passkeyNotAdded: 'That passkey was not added. Try again.' } as const; // `Too many tries…`: `seconds`, the answer's Retry-After, in minutes, rounded up. export function tooManyTries(seconds: number): string { const n = Math.max(1, Math.ceil(seconds / 60)); return `Too many tries. Try again in ${n} ${n === 1 ? 'minute' : 'minutes'}.`; } // The alert for a `sign-in` that signed nothing in, `wrong` being its `400`'s. export function signInAlert(a: Answer, wrong: string): string { if (a.status === 400) return wrong; if (a.status === 429) return tooManyTries(a.retryAfter ?? 60); if (a.status === 507) return alerts.outOfSpace; return alerts.failed; } // The alert for a `consent` or `reject` that answered no `url`. export function leaveAlert(a: Answer): string { if (a.status === 400) return alerts.ended; if (a.status === 507) return alerts.outOfSpace; return alerts.failed; } // The alert for a `passkey-sign-in` that signed nothing in. export function passkeySignInAlert(a: Answer): string { if (a.status === 400) return alerts.passkeyRefused; if (a.status === 507) return alerts.outOfSpace; return alerts.failed; } // The alert for a `passkey-register` that added nothing. export function registerAlert(a: Answer): string { if (a.status === 400) return a.body?.error === 'access_denied' ? alerts.linkEnded : alerts.passkeyNotAdded; if (a.status === 507) return alerts.outOfSpace; return alerts.failed; }