RC-4: move authRoles to src/app/configs

This commit is contained in:
2023-06-22 19:56:33 +01:00
parent b11e5db2e7
commit cc6c57655e
14 changed files with 34 additions and 178 deletions

View File

@@ -1,7 +1,7 @@
import i18next from 'i18next';
import SignInPage from './SignInPage';
import authRoles from '../../../auth/authRoles';
import authRoles from '../../../configs/authRoles';
import en from './i18n/en';
i18next.addResourceBundle('en', 'signInPage', en);

View File

@@ -10,13 +10,14 @@ import Typography from '@mui/material/Typography';
import { Controller, useForm } from 'react-hook-form';
import { withTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { authService } from 'src/app/services';
import * as yup from 'yup';
import LeftSideCanvas from '../shared-components/LeftSideCanvas';
const defaultValues = {
email: '',
password: '',
remember: true,
remember: false,
};
function SignInPage({ t }) {
@@ -25,7 +26,7 @@ function SignInPage({ t }) {
password: yup.string().required(t('password_error')).min(8, t('password_error')),
});
const { control, formState, handleSubmit, reset } = useForm({
const { control, formState, handleSubmit, setError } = useForm({
mode: 'onChange',
defaultValues,
resolver: yupResolver(schema),
@@ -33,8 +34,13 @@ function SignInPage({ t }) {
const { isValid, dirtyFields, errors } = formState;
function onSubmit() {
reset(defaultValues);
function onSubmit(data) {
authService.signInWithEmailAndPassword(data).catch((error) => {
setError('root', {
type: 'manual',
message: error.message,
});
});
}
return (
@@ -145,6 +151,7 @@ function SignInPage({ t }) {
>
{t('sign_in_btn')}
</Button>
{errors.root && <p>{errors.root.message}</p>}
</div>
</form>
</div>

View File

@@ -1,12 +1,12 @@
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
import { useEffect } from 'react';
import JwtService from '../../../auth/services/jwtService';
import { authService } from 'src/app/services';
function SignOutPage() {
useEffect(() => {
setTimeout(() => {
JwtService.logout();
authService.logout();
}, 1000);
}, []);

View File

@@ -1,7 +1,7 @@
import i18next from 'i18next';
import SignUpPage from './SignUpPage';
import authRoles from '../../../auth/authRoles';
import authRoles from '../../../configs/authRoles';
import en from './i18n/en';
i18next.addResourceBundle('en', 'signUpPage', en);

View File

@@ -11,6 +11,7 @@ import Typography from '@mui/material/Typography';
import { Controller, useForm } from 'react-hook-form';
import { withTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { authService } from 'src/app/services';
import * as yup from 'yup';
import LeftSideCanvas from '../shared-components/LeftSideCanvas';
@@ -31,7 +32,7 @@ function SignUpPage({ t }) {
acceptTermsConditions: yup.boolean().oneOf([true], t('accept_terms_error')),
});
const { control, formState, handleSubmit, reset } = useForm({
const { control, formState, handleSubmit, setError } = useForm({
mode: 'onChange',
defaultValues,
resolver: yupResolver(schema),
@@ -39,8 +40,19 @@ function SignUpPage({ t }) {
const { isValid, dirtyFields, errors } = formState;
function onSubmit() {
reset(defaultValues);
function onSubmit({ name, password, email }) {
authService
.createUser({
displayName: name,
password,
email,
})
.catch((error) => {
setError('root', {
type: 'manual',
message: error.message,
});
});
}
return (