Automatically add the domain to the handle during signin
parent
23fd43e306
commit
bc9be64a4e
|
@ -112,17 +112,64 @@ const SigninOrCreateAccount = ({
|
||||||
const Signin = ({onPressBack}: {onPressBack: () => void}) => {
|
const Signin = ({onPressBack}: {onPressBack: () => void}) => {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||||
|
const [serviceDescription, setServiceDescription] = useState<
|
||||||
|
ServiceDescription | undefined
|
||||||
|
>(undefined)
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState<string>('')
|
||||||
const [handle, setHandle] = useState<string>('')
|
const [handle, setHandle] = useState<string>('')
|
||||||
const [password, setPassword] = useState<string>('')
|
const [password, setPassword] = useState<string>('')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let aborted = false
|
||||||
|
if (serviceDescription || error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
store.session.describeService(DEFAULT_SERVICE).then(
|
||||||
|
desc => {
|
||||||
|
if (aborted) return
|
||||||
|
setServiceDescription(desc)
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
if (aborted) return
|
||||||
|
console.error(err)
|
||||||
|
setError(
|
||||||
|
'Unable to contact your service. Please check your Internet connection.',
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return () => {
|
||||||
|
aborted = true
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
const onPressNext = async () => {
|
const onPressNext = async () => {
|
||||||
setError('')
|
setError('')
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
|
|
||||||
|
// try to guess the handle if the user just gave their own username
|
||||||
try {
|
try {
|
||||||
|
let fullHandle = handle
|
||||||
|
if (
|
||||||
|
serviceDescription &&
|
||||||
|
serviceDescription.availableUserDomains.length > 0
|
||||||
|
) {
|
||||||
|
let matched = false
|
||||||
|
for (const domain of serviceDescription.availableUserDomains) {
|
||||||
|
if (fullHandle.endsWith(domain)) {
|
||||||
|
matched = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!matched) {
|
||||||
|
fullHandle = createFullHandle(
|
||||||
|
handle,
|
||||||
|
serviceDescription.availableUserDomains[0],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await store.session.login({
|
await store.session.login({
|
||||||
service: DEFAULT_SERVICE,
|
service: DEFAULT_SERVICE,
|
||||||
handle,
|
handle: fullHandle,
|
||||||
password,
|
password,
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -161,10 +208,10 @@ const Signin = ({onPressBack}: {onPressBack: () => void}) => {
|
||||||
</View>
|
</View>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
<View style={styles.groupContent}>
|
<View style={styles.groupContent}>
|
||||||
<FontAwesomeIcon icon="envelope" style={styles.groupContentIcon} />
|
<FontAwesomeIcon icon="at" style={styles.groupContentIcon} />
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.textInput}
|
style={styles.textInput}
|
||||||
placeholder="Email or username"
|
placeholder="Username"
|
||||||
placeholderTextColor={colors.blue0}
|
placeholderTextColor={colors.blue0}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoFocus
|
autoFocus
|
||||||
|
|
Loading…
Reference in New Issue