-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomponent.tsx
More file actions
56 lines (48 loc) · 1.98 KB
/
component.tsx
File metadata and controls
56 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
import Constants from 'expo-constants';
import { ReactElement, useState } from 'react';
import { AppButton } from '@open-webui-react-native/mobile/shared/ui/ui-kit';
import { authApi } from '@open-webui-react-native/shared/data-access/api';
import { appStorageService } from '@open-webui-react-native/shared/data-access/storage';
import { ronasApiUrl } from '@open-webui-react-native/shared/utils/config';
import { ToastService } from '@open-webui-react-native/shared/utils/toast-service';
GoogleSignin.configure({
iosClientId: Constants.expoConfig?.extra?.googleIosClientId,
});
interface GoogleSignInFormProps {
onSuccess?: () => void;
}
export function GoogleSignInForm({ onSuccess }: GoogleSignInFormProps): ReactElement {
const translate = useTranslation('AUTH.SIGN_IN.GOOGLE_FORM');
const { mutate: signInWithGoogle, isPending: isGoogleAuthRequestLoading } = authApi.useSignInWithGoogle({
onSuccess,
});
const [isGoogleAuthProcessing, setIsGoogleAuthProcessing] = useState(false);
const handleSignInWithGooglePress = async (): Promise<void> => {
try {
setIsGoogleAuthProcessing(true);
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
const signInResponse = await GoogleSignin.signIn();
const email = signInResponse.data?.user?.email;
if (email) {
appStorageService.apiUrl.set(ronasApiUrl);
signInWithGoogle({ email });
} else if (signInResponse.type !== 'cancelled') {
ToastService.showError();
}
} catch {
ToastService.showError();
} finally {
setIsGoogleAuthProcessing(false);
}
};
return (
<AppButton
text={translate('BUTTON_CONTINUE_WITH_GOOGLE')}
iconName='googleLogo'
onPress={handleSignInWithGooglePress}
isLoading={isGoogleAuthProcessing || isGoogleAuthRequestLoading}
/>
);
}