Skip to content

Commit

Permalink
Ham 50 log out user when enters signup page (#204)
Browse files Browse the repository at this point in the history
* fix(app/worker/signout): logout user when visiting sign up page

* fix(app/auth-pages): logout users
  • Loading branch information
KacperKoza343 authored Jul 8, 2024
1 parent 99fe3fc commit 8d3f1ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export function OperatorSignIn() {
isError: isSignInMutationError,
error: signInMutationError,
} = useWeb3SignIn();
const { user } = useWeb3Auth();
const { user, signOut } = useWeb3Auth();
const modalWasOpened = useRef(false);

useEffect(() => {
signOut();
// eslint-disable-next-line react-hooks/exhaustive-deps -- ...
}, []);

useEffect(() => {
if (isConnected && modalWasOpened.current) {
signInMutation({ address, type: PrepareSignatureType.SignIn });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { t } from 'i18next';
import { Link } from 'react-router-dom';
import { useAuth } from '@/auth/use-auth';
import { Button } from '@/components/ui/button';
import { routerPaths } from '@/router/router-paths';

export function WorkerSignIn() {
const { user } = useAuth();

const redirectPath = user
? routerPaths.worker.profile
: routerPaths.worker.signIn;

return (
<Button
component={Link}
Expand All @@ -19,7 +12,7 @@ export function WorkerSignIn() {
sx={{
mb: '1.5625rem',
}}
to={redirectPath}
to={routerPaths.worker.signIn}
variant="contained"
>
{t('homepage.workerSignIn')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grid, Typography } from '@mui/material';
import { zodResolver } from '@hookform/resolvers/zod';
import { useTranslation } from 'react-i18next';
import { t as i18NextT } from 'i18next';
import { Link, useNavigate } from 'react-router-dom';
import { Link } from 'react-router-dom';
import { useEffect } from 'react';
import { PageCard } from '@/components/ui/page-card';
import { Input } from '@/components/data-entry/input';
Expand All @@ -29,14 +29,13 @@ function formattedSignInErrorMessage(unknownError: unknown) {

export function SignInWorkerPage() {
const { t } = useTranslation();
const { user } = useAuth();
const navigate = useNavigate();
const { user, signOut } = useAuth();

useEffect(() => {
if (user) {
navigate(routerPaths.worker.profile, { replace: true });
signOut();
}
}, [navigate, user]);
}, [signOut, user]);

const methods = useForm<SignInDto>({
defaultValues: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import { t } from 'i18next';
import omit from 'lodash/omit';
import { Navigate } from 'react-router-dom';
import { useEffect } from 'react';
import type { SignUpDto } from '@/api/servieces/worker/sign-up';
import {
signUpDtoSchema,
Expand All @@ -32,7 +32,13 @@ function formattedSignUpErrorMessage(unknownError: unknown) {
}

export function SignUpWorkerPage() {
const { user } = useAuth();
const { user, signOut } = useAuth();

useEffect(() => {
if (user) {
signOut();
}
}, [signOut, user]);

const methods = useForm<SignUpDto>({
defaultValues: {
Expand All @@ -56,10 +62,6 @@ export function SignUpWorkerPage() {
signUpWorkerMutate(omit(data, ['confirmPassword']));
};

if (user) {
return <Navigate replace to={routerPaths.worker.profile} />;
}

return (
<PageCard
alert={
Expand Down

0 comments on commit 8d3f1ad

Please sign in to comment.