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
13a00162
Commit
13a00162
authored
Apr 26, 2021
by
Doan Andreas Nathanael
Browse files
[REFACTOR] move set access token cache to signup context instead of manually set token
parent
d5dba640
Pipeline
#72903
passed with stages
in 23 minutes and 39 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/provider/UserContext/index.ts
View file @
13a00162
...
...
@@ -41,8 +41,11 @@ export const useUserContext = (): iUserContext => {
const
signup
=
async
(
registerData
:
RegistrationRequest
)
=>
{
const
response
=
await
signupApi
(
registerData
);
if
(
response
.
success
)
{
setUser
(
response
.
data
!
.
user
as
User
);
if
(
response
.
success
&&
response
.
data
)
{
await
setCache
(
CACHE_KEYS
.
authToken
,
response
.
data
?.
access_token
);
await
setCache
(
CACHE_KEYS
.
refreshToken
,
response
.
data
?.
refresh_token
);
setUser
(
response
.
data
.
user
);
}
return
response
;
...
...
src/scenes/auth/ManualRegistrationPage/index.tsx
View file @
13a00162
...
...
@@ -8,8 +8,6 @@ import { TextField } from 'components/form';
import
{
fieldValidation
,
initialValues
,
textField
}
from
'
./schema
'
;
import
{
generateValidationSchema
}
from
'
utils/form
'
;
import
{
UserContext
}
from
'
provider
'
;
import
{
setCache
}
from
'
utils/cache
'
;
import
CACHE_KEYS
from
'
constants/cacheKeys
'
;
import
{
layoutStyles
}
from
'
styles
'
;
import
{
GoogleLoginButton
}
from
'
../components
'
;
...
...
@@ -32,10 +30,7 @@ const ManualRegistrationPage: FC = () => {
onSubmit
:
async
(
values
)
=>
{
const
response
=
await
signup
(
values
);
if
(
response
.
success
)
{
await
setCache
(
CACHE_KEYS
.
authToken
,
response
.
data
?.
access_token
);
await
setCache
(
CACHE_KEYS
.
refreshToken
,
response
.
data
?.
refresh_token
);
}
else
{
if
(
!
response
.
success
)
{
setFieldError
(
'
name
'
,
response
.
error
.
name
);
setFieldError
(
'
email
'
,
response
.
error
.
email
);
setFieldError
(
'
password1
'
,
response
.
error
.
password1
);
...
...
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