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
PPL Sosial
tbcare
tbcare-mobile
Commits
0f8353b4
Commit
0f8353b4
authored
May 29, 2021
by
Zafir Rasyidi Taufik
Browse files
[GREEN]Added implementation to check if user already exists
parent
96614cbd
Pipeline
#79301
failed with stage
in 53 minutes and 22 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
src/scenes/LoginPage/__snapshots__/index.test.tsx.snap
View file @
0f8353b4
This diff is collapsed.
Click to expand it.
src/scenes/LoginPage/index.tsx
View file @
0f8353b4
...
...
@@ -40,21 +40,56 @@ const LoginPage = () => {
});
const
[
userInfo
,
setUserInfo
]
=
useState
<
any
>
();
const
signIn
=
async
()
=>
{
const
checkIfTokenHasCorrespondingUser
=
async
(
idToken
:
string
|
null
)
=>
{
setShouldLoading
(
true
)
const
checkRes
=
await
services
.
main
.
checkGoogleUserExists
({
token
:
idToken
});
setShouldLoading
(
false
)
if
(
checkRes
===
undefined
)
{
setAlert
({
illustration
:
WonderingIllustration
,
message
:
LoginResponse
.
NoInternetConn
,
})
}
else
{
if
(
checkRes
.
status
===
200
)
{
LocalStorage
.
setItem
(
'
token
'
,
checkRes
.
data
.
token
);
setToken
(
checkRes
.
data
.
token
);
return
false
;
}
else
if
(
checkRes
.
status
===
500
)
{
setAlert
({
illustration
:
WonderingIllustration
,
message
:
LoginResponse
.
UnknownServerError
,
})
return
false
;
}
else
{
return
true
;
}
}
}
const
signInWithGoogle
=
async
()
=>
{
try
{
await
GoogleSignin
.
hasPlayServices
();
const
tempUserInfo
=
await
GoogleSignin
.
signIn
();
setUserInfo
(
tempUserInfo
);
navigation
.
navigate
(
'
officer-signup-form-google-signin
'
,
{
idToken
:
tempUserInfo
.
idToken
});
const
noGoogleUser
=
await
checkIfTokenHasCorrespondingUser
(
tempUserInfo
.
idToken
);
if
(
noGoogleUser
)
navigation
.
navigate
(
'
officer-signup-form-google-signin
'
,
{
idToken
:
tempUserInfo
.
idToken
});
}
catch
(
error
)
{
console
.
log
(
error
)
if
(
error
.
code
===
statusCodes
.
SIGN_IN_CANCELLED
)
{
// user cancelled the login flow
}
else
if
(
error
.
code
===
statusCodes
.
IN_PROGRESS
)
{
// operation (e.g. sign in) is in progress already
}
else
if
(
error
.
code
===
statusCodes
.
PLAY_SERVICES_NOT_AVAILABLE
)
{
// play services not available or outdated
setAlert
({
illustration
:
WonderingIllustration
,
message
:
"
Play Service sedang tidak tersedia, coba lagi nanti
"
,
})
}
else
{
}
}
...
...
@@ -180,7 +215,7 @@ const LoginPage = () => {
style
=
{
{
width
:
192
,
height
:
48
}
}
size
=
{
GoogleSigninButton
.
Size
.
Wide
}
color
=
{
GoogleSigninButton
.
Color
.
Dark
}
onPress
=
{
()
=>
signIn
()
}
onPress
=
{
()
=>
signIn
WithGoogle
()
}
/>
</
Box
>
</
Action
>
...
...
src/scenes/OfficerSignupFormGoogleSignin/index.tsx
View file @
0f8353b4
...
...
@@ -142,7 +142,7 @@ const OfficerSignupFormGoogleSignin = () => {
setIsLoading
(
true
)
const
response
=
await
global
.
services
.
main
.
createUserGoogleSignin
({
idT
oken
:
route
.
params
.
idToken
,
t
oken
:
route
.
params
.
idToken
,
phone_number
:
form
.
fields
.
phone_number
.
value
,
district
:
form
.
fields
.
district
.
value
,
sub_district
:
form
.
fields
.
sub_district
.
value
...
...
src/services/hooks/useMainService/index.tsx
View file @
0f8353b4
...
...
@@ -10,6 +10,7 @@ const END_POINTS = {
LIST_POSITIVE_CASES
:
createEndpoint
([
"
cases
"
,
"
positive-cases
"
]),
MONITORING_CASES
:
createEndpoint
([
"
cases
"
,
"
monitoring-cases
"
]),
LOGS
:
createEndpoint
([
"
logs
"
]),
GOOGLE
:
createEndpoint
([
"
google
"
]),
LOGIN
:
'
/auth/token/
'
,
};
...
...
@@ -89,7 +90,7 @@ export default function useMainService(idToken: string) {
}
interface
UserFormTypeGoogleSignin
{
idT
oken
:
string
t
oken
:
string
phone_number
:
string
;
district
:
string
;
sub_district
:
string
;
...
...
@@ -102,6 +103,17 @@ export default function useMainService(idToken: string) {
return
fetchWithoutAuthentication
(
endPoint
,
Method
.
POST
,
body
);
}
interface
CheckGoogleTokenType
{
token
:
string
}
async
function
checkGoogleUserExists
(
body
:
CheckGoogleTokenType
)
{
const
endPoint
=
END_POINTS
.
GOOGLE
([
null
,
])
return
fetchWithoutAuthentication
(
endPoint
,
Method
.
POST
,
body
);
}
async
function
createCaseSubject
(
body
:
object
)
{
const
endPoint
=
END_POINTS
.
CASE_SUBJECTS
([
null
,
...
...
@@ -275,6 +287,7 @@ export default function useMainService(idToken: string) {
login
,
createUser
,
createUserGoogleSignin
,
checkGoogleUserExists
,
me
,
// Contact Investigation Form
createCaseSubject
,
...
...
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