Fakultas Ilmu Komputer UI

Commit 13a00162 authored by Doan Andreas Nathanael's avatar 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
......@@ -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;
......
......@@ -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);
......
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