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 => { ...@@ -120,7 +120,7 @@ export const useUserContext = (): iUserContext => {
return response; return response;
}; };
const loginWithGoogle = async () => { const loginWithGoogle = async (isLogin: boolean = true) => {
try { try {
await GoogleSignin.hasPlayServices(); await GoogleSignin.hasPlayServices();
await GoogleSignin.signIn(); await GoogleSignin.signIn();
...@@ -130,15 +130,18 @@ export const useUserContext = (): iUserContext => { ...@@ -130,15 +130,18 @@ export const useUserContext = (): iUserContext => {
}); });
if (response.success && response.data) { if (response.success && response.data) {
await authSuccess(response.data); await authSuccess(response.data);
if (!isLogin) {
const linkResponse = await linkUserData(response.data.user.email); const linkResponse = await linkUserData(response.data.user.email);
if (!linkResponse.success) { if (!linkResponse.success) {
await logout(); await logout();
Toast.show({ Toast.show({
type: 'error', type: 'error',
text1: 'Gagal masuk dengan Google', text1: 'Gagal registrasi dengan Google',
text2: 'Terjadi kesalahan di sisi kami. Silakan coba lagi', text2: 'Terjadi kesalahan di sisi kami. Silakan coba lagi',
}); });
} }
}
} else { } else {
await logout(); await logout();
} }
......
...@@ -20,6 +20,6 @@ export interface iUserContext { ...@@ -20,6 +20,6 @@ export interface iUserContext {
data: RegistrationRequest, data: RegistrationRequest,
) => ApiResponse<LoginResponse | LinkUserDataResponse>; ) => ApiResponse<LoginResponse | LinkUserDataResponse>;
login: (data: LoginRequest) => ApiResponse<LoginResponse>; login: (data: LoginRequest) => ApiResponse<LoginResponse>;
loginWithGoogle: () => Promise<void>; loginWithGoogle: (_?: boolean) => Promise<void>;
logout: () => Promise<void>; logout: () => Promise<void>;
} }
...@@ -45,6 +45,8 @@ const ManualRegistrationPage: FC = () => { ...@@ -45,6 +45,8 @@ const ManualRegistrationPage: FC = () => {
}, },
}); });
const signupWithGoogle = () => loginWithGoogle(false);
useAuthEffect(); useAuthEffect();
return ( return (
...@@ -66,7 +68,7 @@ const ManualRegistrationPage: FC = () => { ...@@ -66,7 +68,7 @@ const ManualRegistrationPage: FC = () => {
testID="submitButton" testID="submitButton"
/> />
<Section> <Section>
<GoogleLoginButton onPress={loginWithGoogle} isLoading={isLoading} /> <GoogleLoginButton onPress={signupWithGoogle} isLoading={isLoading} />
</Section> </Section>
</ScrollView> </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