Update login to use new session.create api, which enables email login (close #93)

This commit is contained in:
Paul Frazee
2023-01-31 09:03:22 -06:00
parent 0d8a7cd816
commit b1b6f9c51c
4 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -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",
+3 -3
View File
@@ -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,
+11 -10
View File
@@ -261,7 +261,7 @@ const LoginForm = ({
const {track} = useAnalytics()
const pal = usePalette('default')
const [isProcessing, setIsProcessing] = useState<boolean>(false)
const [handle, setHandle] = useState<string>(initialHandle)
const [identifier, setIdentifier] = useState<string>(initialHandle)
const [password, setPassword] = useState<string>('')
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 (
<View testID="loginForm">
<LogoTextHero />
@@ -354,13 +355,13 @@ const LoginForm = ({
<TextInput
testID="loginUsernameInput"
style={[pal.text, styles.textInput]}
placeholder="Username"
placeholder="Username or email address"
placeholderTextColor={pal.colors.textLight}
autoCapitalize="none"
autoFocus
autoCorrect={false}
value={handle}
onChangeText={str => setHandle((str || '').toLowerCase())}
value={identifier}
onChangeText={str => setIdentifier((str || '').toLowerCase())}
editable={!isProcessing}
/>
</View>
+4 -5
View File
@@ -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" "*"