Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Mobile
Commits
b9d1633d
Commit
b9d1633d
authored
Apr 26, 2021
by
Wulan Mantiri
Browse files
[REFACTOR] Fix google signup logic to only link when called in registration page
parent
4fb5fa03
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/provider/UserContext/index.ts
View file @
b9d1633d
...
...
@@ -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,14 +130,17 @@ export const useUserContext = (): iUserContext => {
});
if
(
response
.
success
&&
response
.
data
)
{
await
authSuccess
(
response
.
data
);
const
linkResponse
=
await
linkUserData
(
response
.
data
.
user
.
email
);
if
(
!
linkResponse
.
success
)
{
await
logout
();
Toast
.
show
({
type
:
'
error
'
,
text1
:
'
Gagal masuk dengan Google
'
,
text2
:
'
Terjadi kesalahan di sisi kami. Silakan coba lagi
'
,
});
if
(
!
isLogin
)
{
const
linkResponse
=
await
linkUserData
(
response
.
data
.
user
.
email
);
if
(
!
linkResponse
.
success
)
{
await
logout
();
Toast
.
show
({
type
:
'
error
'
,
text1
:
'
Gagal registrasi dengan Google
'
,
text2
:
'
Terjadi kesalahan di sisi kami. Silakan coba lagi
'
,
});
}
}
}
else
{
await
logout
();
...
...
src/provider/UserContext/types.ts
View file @
b9d1633d
...
...
@@ -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
>
;
}
src/scenes/auth/ManualRegistrationPage/index.tsx
View file @
b9d1633d
...
...
@@ -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
=
{
login
WithGoogle
}
isLoading
=
{
isLoading
}
/>
<
GoogleLoginButton
onPress
=
{
signup
WithGoogle
}
isLoading
=
{
isLoading
}
/>
</
Section
>
</
ScrollView
>
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment