Fakultas Ilmu Komputer UI

Commit b9d1633d authored by Wulan Mantiri's avatar Wulan Mantiri
Browse files

[REFACTOR] Fix google signup logic to only link when called in registration page

parent 4fb5fa03
......@@ -120,7 +120,7 @@ export const useUserContext = (): iUserContext => {
return response;
};
const loginWithGoogle = async () => {
const loginWithGoogle = async (isLogin: boolean = true) => {
try {
await GoogleSignin.hasPlayServices();
await GoogleSignin.signIn();
......@@ -130,15 +130,18 @@ export const useUserContext = (): iUserContext => {
});
if (response.success && response.data) {
await authSuccess(response.data);
if (!isLogin) {
const linkResponse = await linkUserData(response.data.user.email);
if (!linkResponse.success) {
await logout();
Toast.show({
type: 'error',
text1: 'Gagal masuk dengan Google',
text1: 'Gagal registrasi dengan Google',
text2: 'Terjadi kesalahan di sisi kami. Silakan coba lagi',
});
}
}
} else {
await logout();
}
......
......@@ -20,6 +20,6 @@ export interface iUserContext {
data: RegistrationRequest,
) => ApiResponse<LoginResponse | LinkUserDataResponse>;
login: (data: LoginRequest) => ApiResponse<LoginResponse>;
loginWithGoogle: () => Promise<void>;
loginWithGoogle: (_?: boolean) => Promise<void>;
logout: () => Promise<void>;
}
......@@ -45,6 +45,8 @@ const ManualRegistrationPage: FC = () => {
},
});
const signupWithGoogle = () => loginWithGoogle(false);
useAuthEffect();
return (
......@@ -66,7 +68,7 @@ const ManualRegistrationPage: FC = () => {
testID="submitButton"
/>
<Section>
<GoogleLoginButton onPress={loginWithGoogle} isLoading={isLoading} />
<GoogleLoginButton onPress={signupWithGoogle} isLoading={isLoading} />
</Section>
</ScrollView>
);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment