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

This commit is contained in:
Paul Frazee
2023-01-31 10:38:43 -06:00
committed by GitHub
parent 26a4f85fda
commit 9302940a23
4 changed files with 19 additions and 19 deletions
+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>