From d2c42cf16905a8904dcfbba4825ca5f8abc3f253 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 24 May 2024 00:10:13 +0100 Subject: [PATCH] Privileged app passwords (#4200) * add checkbox to create privileged app password * add indicator to privileged app pwds to list * bump api * oops missed the yarnlock * adjust modal padding * lowercase * one more lowercase --------- Co-authored-by: Hailey --- package.json | 2 +- src/state/queries/app-passwords.ts | 5 +- src/view/com/modals/AddAppPasswords.tsx | 187 +++++++++++++----------- src/view/screens/AppPasswords.tsx | 53 ++++--- yarn.lock | 8 +- 5 files changed, 145 insertions(+), 110 deletions(-) diff --git a/package.json b/package.json index 2680b2d1..4c79e29f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web" }, "dependencies": { - "@atproto/api": "^0.12.11", + "@atproto/api": "^0.12.13", "@bam.tech/react-native-image-resizer": "^3.0.4", "@braintree/sanitize-url": "^6.0.2", "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet", diff --git a/src/state/queries/app-passwords.ts b/src/state/queries/app-passwords.ts index a8f8fba0..33009a3a 100644 --- a/src/state/queries/app-passwords.ts +++ b/src/state/queries/app-passwords.ts @@ -25,12 +25,13 @@ export function useAppPasswordCreateMutation() { return useMutation< ComAtprotoServerCreateAppPassword.OutputSchema, Error, - {name: string} + {name: string; privileged: boolean} >({ - mutationFn: async ({name}) => { + mutationFn: async ({name, privileged}) => { return ( await getAgent().com.atproto.server.createAppPassword({ name, + privileged, }) ).data }, diff --git a/src/view/com/modals/AddAppPasswords.tsx b/src/view/com/modals/AddAppPasswords.tsx index e6f424ed..d6df1265 100644 --- a/src/view/com/modals/AddAppPasswords.tsx +++ b/src/view/com/modals/AddAppPasswords.tsx @@ -8,20 +8,23 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {usePalette} from '#/lib/hooks/usePalette' +import {s} from '#/lib/styles' import {logger} from '#/logger' +import {isNative} from '#/platform/detection' import {useModalControls} from '#/state/modals' import { useAppPasswordCreateMutation, useAppPasswordsQuery, } from '#/state/queries/app-passwords' -import {usePalette} from 'lib/hooks/usePalette' -import {s} from 'lib/styles' -import {isNative} from 'platform/detection' -import {Button} from '../util/forms/Button' -import {Text} from '../util/text/Text' -import * as Toast from '../util/Toast' +import {Button} from '#/view/com/util/forms/Button' +import {Text} from '#/view/com/util/text/Text' +import * as Toast from '#/view/com/util/Toast' +import {atoms as a} from '#/alf' +import * as Toggle from '#/components/forms/Toggle' +import {KeyboardPadding} from '#/components/KeyboardPadding' -export const snapPoints = ['70%'] +export const snapPoints = ['90%'] const shadesOfBlue: string[] = [ 'AliceBlue', @@ -70,6 +73,7 @@ export function Component({}: {}) { ) const [appPassword, setAppPassword] = useState() const [wasCopied, setWasCopied] = useState(false) + const [privileged, setPrivileged] = useState(false) const onCopy = React.useCallback(() => { if (appPassword) { @@ -109,7 +113,7 @@ export function Component({}: {}) { } try { - const newPassword = await mutateAppPassword({name}) + const newPassword = await mutateAppPassword({name, privileged}) if (newPassword) { setAppPassword(newPassword.password) } else { @@ -140,86 +144,98 @@ export function Component({}: {}) { return ( - - {!appPassword ? ( - - - Please enter a unique name for this App Password or use our - randomly generated one. - - - ) : ( - - - Here is your app password. + {!appPassword ? ( + <> + + + + Please enter a unique name for this App Password or use our + randomly generated one. + - - Use this to sign into the other app along with your handle. - - - )} - {!appPassword ? ( - - - - ) : ( - - - {appPassword} - - {wasCopied ? ( - - Copied - - ) : ( - + - )} - - )} - - {appPassword ? ( - - - For security reasons, you won't be able to view this again. If you - lose this password, you'll need to generate a new one. - - + + + + + Can only contain letters, numbers, spaces, dashes, and + underscores. Must be at least 4 characters long, but no more than + 32 characters long. + + + setPrivileged(val)} + name="privileged" + style={a.my_md}> + + + Allow access to your direct messages + + + ) : ( - - - Can only contain letters, numbers, spaces, dashes, and underscores. - Must be at least 4 characters long, but no more than 32 characters - long. - - + <> + + + + Here is your app password. + + + Use this to sign into the other app along with your handle. + + + + + {appPassword} + + {wasCopied ? ( + + Copied + + ) : ( + + )} + + + + + For security reasons, you won't be able to view this again. If you + lose this password, you'll need to generate a new one. + + + )}