add auth session browser for native

This commit is contained in:
Hailey
2024-04-02 15:54:56 -07:00
parent 103d441f08
commit 6856b76656
3 changed files with 29 additions and 21 deletions
+4 -21
View File
@@ -7,6 +7,7 @@ import {useLingui} from '@lingui/react'
import {useAnalytics} from '#/lib/analytics/analytics' import {useAnalytics} from '#/lib/analytics/analytics'
import {isAndroid} from 'platform/detection' import {isAndroid} from 'platform/detection'
import {useLogin} from '#/screens/Login/hooks/useLogin'
import {atoms as a} from '#/alf' import {atoms as a} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
import {FormError} from '#/components/forms/FormError' import {FormError} from '#/components/forms/FormError'
@@ -32,10 +33,10 @@ export const LoginForm = ({
setServiceUrl: (v: string) => void setServiceUrl: (v: string) => void
onPressRetryConnect: () => void onPressRetryConnect: () => void
onPressBack: () => void onPressBack: () => void
onPressForgotPassword: () => void
}) => { }) => {
const {track} = useAnalytics() const {track} = useAnalytics()
const {_} = useLingui() const {_} = useLingui()
const {openAuthSession} = useLogin(serviceUrl)
// This improves speed at which the browser presents itself on Android // This improves speed at which the browser presents itself on Android
React.useEffect(() => { React.useEffect(() => {
@@ -49,24 +50,6 @@ export const LoginForm = ({
track('Signin:PressedSelectService') track('Signin:PressedSelectService')
}, [track]) }, [track])
const onPressNext = async () => {
const authSession = await Browser.openAuthSessionAsync(
'https://bsky.app/login', // Replace this with the PDS auth url
'bsky://login', // Replace this as well with the appropriate link
{
windowFeatures: {},
},
)
if (authSession.type !== 'success') {
return
}
// Handle session storage here
}
console.log(serviceDescription)
return ( return (
<FormContainer testID="loginForm" title={<Trans>Sign in</Trans>}> <FormContainer testID="loginForm" title={<Trans>Sign in</Trans>}>
<View> <View>
@@ -80,7 +63,7 @@ export const LoginForm = ({
/> />
</View> </View>
<FormError error={error} /> <FormError error={error} />
<View style={[a.flex_row, a.align_center, a.justify_between, a.pt_md]}> <View style={[a.flex_row, a.align_center, a.justify_between, a.pt_5xl]}>
<Button <Button
label={_(msg`Back`)} label={_(msg`Back`)}
variant="solid" variant="solid"
@@ -96,7 +79,7 @@ export const LoginForm = ({
variant="solid" variant="solid"
color="primary" color="primary"
size="medium" size="medium"
onPress={onPressNext} onPress={openAuthSession}
disabled={!serviceDescription}> disabled={!serviceDescription}>
<ButtonText> <ButtonText>
<Trans>Sign In</Trans> <Trans>Sign In</Trans>
+25
View File
@@ -0,0 +1,25 @@
import React from 'react'
import * as Browser from 'expo-web-browser'
// Service URL here is just a placeholder, this isn't how it will actually work
export function useLogin(serviceUrl: string | undefined) {
const openAuthSession = React.useCallback(async () => {
if (!serviceUrl) return
const authSession = await Browser.openAuthSessionAsync(
serviceUrl, // This isn't actually how this will work
'bsky://login', // Replace this as well with the appropriate link
{
windowFeatures: {},
},
)
if (authSession.type !== 'success') {
return
}
}, [serviceUrl])
return {
openAuthSession,
}
}