From b1b6f9c51c017c77e61eb8aa1fd1009ec5589eea Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 31 Jan 2023 09:03:22 -0600 Subject: [PATCH] Update login to use new session.create api, which enables email login (close #93) --- package.json | 2 +- src/state/models/session.ts | 6 +++--- src/view/com/login/Signin.tsx | 21 +++++++++++---------- yarn.lock | 9 ++++----- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index c52dff6f15..6e9ae2b5c8 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "zod": "^3.20.2" }, "devDependencies": { - "@atproto/pds": "^0.0.1", + "@atproto/pds": "^0.0.2", "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", diff --git a/src/state/models/session.ts b/src/state/models/session.ts index 075e8c711e..babae9c946 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -244,15 +244,15 @@ export class SessionModel { */ async login({ service, - handle, + identifier, password, }: { service: string - handle: string + identifier: string password: string }) { const api = AtpApi.service(service) - const res = await api.com.atproto.session.create({handle, password}) + const res = await api.com.atproto.session.create({identifier, password}) if (res.data.accessJwt && res.data.refreshJwt) { this.setState({ service: service, diff --git a/src/view/com/login/Signin.tsx b/src/view/com/login/Signin.tsx index 64a41a1a34..c72bd31db4 100644 --- a/src/view/com/login/Signin.tsx +++ b/src/view/com/login/Signin.tsx @@ -261,7 +261,7 @@ const LoginForm = ({ const {track} = useAnalytics() const pal = usePalette('default') const [isProcessing, setIsProcessing] = useState(false) - const [handle, setHandle] = useState(initialHandle) + const [identifier, setIdentifier] = useState(initialHandle) const [password, setPassword] = useState('') const onPressSelectService = () => { @@ -275,20 +275,21 @@ const LoginForm = ({ try { // try to guess the handle if the user just gave their own username - let fullHandle = handle + let fullIdent = identifier if ( + !identifier.includes('@') && // not an email serviceDescription && serviceDescription.availableUserDomains.length > 0 ) { let matched = false for (const domain of serviceDescription.availableUserDomains) { - if (fullHandle.endsWith(domain)) { + if (fullIdent.endsWith(domain)) { matched = true } } if (!matched) { - fullHandle = createFullHandle( - handle, + fullIdent = createFullHandle( + identifier, serviceDescription.availableUserDomains[0], ) } @@ -296,7 +297,7 @@ const LoginForm = ({ await store.session.login({ service: serviceUrl, - handle: fullHandle, + identifier: fullIdent, password, }) track('Sign In', {resumedSession: false}) @@ -316,7 +317,7 @@ const LoginForm = ({ } } - const isReady = !!serviceDescription && !!handle && !!password + const isReady = !!serviceDescription && !!identifier && !!password return ( @@ -354,13 +355,13 @@ const LoginForm = ({ setHandle((str || '').toLowerCase())} + value={identifier} + onChangeText={str => setIdentifier((str || '').toLowerCase())} editable={!isProcessing} /> diff --git a/yarn.lock b/yarn.lock index 1733714fb2..e778606666 100644 --- a/yarn.lock +++ b/yarn.lock @@ -90,12 +90,11 @@ resolved "https://registry.yarnpkg.com/@atproto/nsid/-/nsid-0.0.1.tgz#0cdc00cefe8f0b1385f352b9f57b3ad37fff09a4" integrity sha512-t5M6/CzWBVYoBbIvfKDpqPj/+ZmyoK9ydZSStcTXosJ27XXwOPhz0VDUGKK2SM9G5Y7TPes8S5KTAU0UdVYFCw== -"@atproto/pds@^0.0.1": - version "0.0.1" - resolved "https://registry.yarnpkg.com/@atproto/pds/-/pds-0.0.1.tgz#4492595cd0796a3dc4c10836cd121bb3b132f858" - integrity sha512-8CaAIBzri05CN2gkMtXnUlNxCdUwaWp1qz4b9RXpMQ83Pk1+j3nw09fsml0kjlMCPcWokTF+iGJXrrTL3XVjOw== +"@atproto/pds@^0.0.2": + version "0.0.2" + resolved "https://registry.yarnpkg.com/@atproto/pds/-/pds-0.0.2.tgz#3665a24ce1f3a5696e46fea5448c5f849e38b7e0" + integrity sha512-TCTVKJWaUxF6EQJ6hobhO19bLaoW2Nk8xn/mySnQMN7ZHlYD9Hv+eRVY+PWLpnAuGetCkTbZAspg84eG2lKGTA== dependencies: - "@atproto/auth" "*" "@atproto/common" "*" "@atproto/crypto" "*" "@atproto/did-resolver" "*"