mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: sync the isVerified state of authed user
This commit is contained in:
@@ -3,12 +3,20 @@ import React from 'react';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { useIsAuthenticated } from '@/hooks/state';
|
||||
|
||||
interface PrivateRouteProps {
|
||||
interface EnsureAuthNotAuthenticatedProps {
|
||||
children: React.ReactNode;
|
||||
redirectTo?: string;
|
||||
}
|
||||
|
||||
export function EnsureAuthNotAuthenticated({ children }: PrivateRouteProps) {
|
||||
export function EnsureAuthNotAuthenticated({
|
||||
children,
|
||||
redirectTo = '/',
|
||||
}: EnsureAuthNotAuthenticatedProps) {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
|
||||
return !isAuthenticated ? children : <Redirect to={{ pathname: '/' }} />;
|
||||
return !isAuthenticated ? (
|
||||
<>{children}</>
|
||||
) : (
|
||||
<Redirect to={{ pathname: redirectTo }} />
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import BodyClassName from 'react-body-classname';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { useIsAuthenticated } from '@/hooks/state';
|
||||
|
||||
interface PrivateRouteProps {
|
||||
interface EnsureAuthenticatedProps {
|
||||
children: React.ReactNode;
|
||||
redirectTo?: string;
|
||||
}
|
||||
|
||||
export default function PrivateRoute({ children }: PrivateRouteProps) {
|
||||
export function EnsureAuthenticated({
|
||||
children,
|
||||
redirectTo = '/auth/login',
|
||||
}: EnsureAuthenticatedProps) {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
|
||||
return isAuthenticated ? (
|
||||
children
|
||||
<>{children}</>
|
||||
) : (
|
||||
<Redirect to={{ pathname: '/auth/login' }} />
|
||||
<Redirect to={{ pathname: redirectTo }} />
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { useAuthUserVerified } from '@/hooks/state';
|
||||
|
||||
interface EnsureUserEmailVerifiedProps {
|
||||
children: React.ReactNode;
|
||||
redirectTo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12,11 +13,12 @@ interface EnsureUserEmailVerifiedProps {
|
||||
*/
|
||||
export function EnsureUserEmailVerified({
|
||||
children,
|
||||
redirectTo = '/auth/register/verify',
|
||||
}: EnsureUserEmailVerifiedProps) {
|
||||
const isAuthVerified = useAuthUserVerified();
|
||||
|
||||
if (!isAuthVerified) {
|
||||
return <Redirect to={{ pathname: '/register/verify' }} />;
|
||||
return <Redirect to={{ pathname: redirectTo }} />;
|
||||
}
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user