Update login to use new session.create api, which enables email login (close #93)
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@
|
|||||||
"zod": "^3.20.2"
|
"zod": "^3.20.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@atproto/pds": "^0.0.1",
|
"@atproto/pds": "^0.0.2",
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
"@babel/preset-env": "^7.20.0",
|
"@babel/preset-env": "^7.20.0",
|
||||||
"@babel/runtime": "^7.20.0",
|
"@babel/runtime": "^7.20.0",
|
||||||
|
|||||||
@@ -244,15 +244,15 @@ export class SessionModel {
|
|||||||
*/
|
*/
|
||||||
async login({
|
async login({
|
||||||
service,
|
service,
|
||||||
handle,
|
identifier,
|
||||||
password,
|
password,
|
||||||
}: {
|
}: {
|
||||||
service: string
|
service: string
|
||||||
handle: string
|
identifier: string
|
||||||
password: string
|
password: string
|
||||||
}) {
|
}) {
|
||||||
const api = AtpApi.service(service)
|
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) {
|
if (res.data.accessJwt && res.data.refreshJwt) {
|
||||||
this.setState({
|
this.setState({
|
||||||
service: service,
|
service: service,
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ const LoginForm = ({
|
|||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||||
const [handle, setHandle] = useState<string>(initialHandle)
|
const [identifier, setIdentifier] = useState<string>(initialHandle)
|
||||||
const [password, setPassword] = useState<string>('')
|
const [password, setPassword] = useState<string>('')
|
||||||
|
|
||||||
const onPressSelectService = () => {
|
const onPressSelectService = () => {
|
||||||
@@ -275,20 +275,21 @@ const LoginForm = ({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// try to guess the handle if the user just gave their own username
|
// try to guess the handle if the user just gave their own username
|
||||||
let fullHandle = handle
|
let fullIdent = identifier
|
||||||
if (
|
if (
|
||||||
|
!identifier.includes('@') && // not an email
|
||||||
serviceDescription &&
|
serviceDescription &&
|
||||||
serviceDescription.availableUserDomains.length > 0
|
serviceDescription.availableUserDomains.length > 0
|
||||||
) {
|
) {
|
||||||
let matched = false
|
let matched = false
|
||||||
for (const domain of serviceDescription.availableUserDomains) {
|
for (const domain of serviceDescription.availableUserDomains) {
|
||||||
if (fullHandle.endsWith(domain)) {
|
if (fullIdent.endsWith(domain)) {
|
||||||
matched = true
|
matched = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
fullHandle = createFullHandle(
|
fullIdent = createFullHandle(
|
||||||
handle,
|
identifier,
|
||||||
serviceDescription.availableUserDomains[0],
|
serviceDescription.availableUserDomains[0],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -296,7 +297,7 @@ const LoginForm = ({
|
|||||||
|
|
||||||
await store.session.login({
|
await store.session.login({
|
||||||
service: serviceUrl,
|
service: serviceUrl,
|
||||||
handle: fullHandle,
|
identifier: fullIdent,
|
||||||
password,
|
password,
|
||||||
})
|
})
|
||||||
track('Sign In', {resumedSession: false})
|
track('Sign In', {resumedSession: false})
|
||||||
@@ -316,7 +317,7 @@ const LoginForm = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isReady = !!serviceDescription && !!handle && !!password
|
const isReady = !!serviceDescription && !!identifier && !!password
|
||||||
return (
|
return (
|
||||||
<View testID="loginForm">
|
<View testID="loginForm">
|
||||||
<LogoTextHero />
|
<LogoTextHero />
|
||||||
@@ -354,13 +355,13 @@ const LoginForm = ({
|
|||||||
<TextInput
|
<TextInput
|
||||||
testID="loginUsernameInput"
|
testID="loginUsernameInput"
|
||||||
style={[pal.text, styles.textInput]}
|
style={[pal.text, styles.textInput]}
|
||||||
placeholder="Username"
|
placeholder="Username or email address"
|
||||||
placeholderTextColor={pal.colors.textLight}
|
placeholderTextColor={pal.colors.textLight}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoFocus
|
autoFocus
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
value={handle}
|
value={identifier}
|
||||||
onChangeText={str => setHandle((str || '').toLowerCase())}
|
onChangeText={str => setIdentifier((str || '').toLowerCase())}
|
||||||
editable={!isProcessing}
|
editable={!isProcessing}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -90,12 +90,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@atproto/nsid/-/nsid-0.0.1.tgz#0cdc00cefe8f0b1385f352b9f57b3ad37fff09a4"
|
resolved "https://registry.yarnpkg.com/@atproto/nsid/-/nsid-0.0.1.tgz#0cdc00cefe8f0b1385f352b9f57b3ad37fff09a4"
|
||||||
integrity sha512-t5M6/CzWBVYoBbIvfKDpqPj/+ZmyoK9ydZSStcTXosJ27XXwOPhz0VDUGKK2SM9G5Y7TPes8S5KTAU0UdVYFCw==
|
integrity sha512-t5M6/CzWBVYoBbIvfKDpqPj/+ZmyoK9ydZSStcTXosJ27XXwOPhz0VDUGKK2SM9G5Y7TPes8S5KTAU0UdVYFCw==
|
||||||
|
|
||||||
"@atproto/pds@^0.0.1":
|
"@atproto/pds@^0.0.2":
|
||||||
version "0.0.1"
|
version "0.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/@atproto/pds/-/pds-0.0.1.tgz#4492595cd0796a3dc4c10836cd121bb3b132f858"
|
resolved "https://registry.yarnpkg.com/@atproto/pds/-/pds-0.0.2.tgz#3665a24ce1f3a5696e46fea5448c5f849e38b7e0"
|
||||||
integrity sha512-8CaAIBzri05CN2gkMtXnUlNxCdUwaWp1qz4b9RXpMQ83Pk1+j3nw09fsml0kjlMCPcWokTF+iGJXrrTL3XVjOw==
|
integrity sha512-TCTVKJWaUxF6EQJ6hobhO19bLaoW2Nk8xn/mySnQMN7ZHlYD9Hv+eRVY+PWLpnAuGetCkTbZAspg84eG2lKGTA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@atproto/auth" "*"
|
|
||||||
"@atproto/common" "*"
|
"@atproto/common" "*"
|
||||||
"@atproto/crypto" "*"
|
"@atproto/crypto" "*"
|
||||||
"@atproto/did-resolver" "*"
|
"@atproto/did-resolver" "*"
|
||||||
|
|||||||
Reference in New Issue
Block a user