Skip to content

Commit

Permalink
chore: now when you press login you will be redirected to the profile…
Browse files Browse the repository at this point in the history
… if you are authenticated
  • Loading branch information
Franqsanz committed Jan 26, 2024
1 parent 4a2f967 commit 8add472
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@chakra-ui/react';

import { MainHead } from '@components/Head';
import { useAuth } from '@contexts/AuthContext';
import {
PatternPadWhite,
PatternPadBlack,
Expand All @@ -27,6 +28,7 @@ import {

export function Home() {
const { colorMode } = useColorMode();
const { currentUser } = useAuth();
const bgButton = useColorModeValue('green.500', 'green.700');
const bContainer = useColorModeValue('gray.50', 'none');
const height = useBreakpointValue({
Expand Down Expand Up @@ -88,7 +90,7 @@ export function Home() {
>
<Link
w={{ base: '250px', md: '200px' }}
to='/login'
to={!currentUser ? '/login' : `/profile/${currentUser?.uid}`}
as={NavLink}
border='1px'
bg={bgButton}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { SignIn } from '@services/firebase/auth';
export function Login() {
return (
<>
<MainHead title='Ingresar | XBuniverse' />
<ContainerTitle title='Ingresar' />
<MainHead title='Ingresar o Regístrate| XBuniverse' />
<ContainerTitle title='Ingresar o Regístrate' />
<Flex
justify='center'
// py={{ base: '10vh', md: '31vh' }}
Expand Down
38 changes: 4 additions & 34 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { lazy, useState } from 'react';
import { createBrowserRouter, Navigate, useLocation } from 'react-router-dom';
import React, { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom';

import { Home } from '@pages/Home';
import { Register } from '@pages/Register';
import { Login } from '@pages/Login';
import { CatchError } from '@utils/CatchError';
import { ErrorPage } from '@pages/404';
Expand All @@ -11,42 +10,21 @@ import { SkeletonAllBooks } from '@components/skeletons/SkeletonABooks';
import { SkeletonDetailsBook } from '@components/skeletons/SkeletonDBook';
import { PrivateRoute } from '@components/PrivateRoute';

import { useAuth } from '@contexts/AuthContext';

const PrivacyPolicies = lazy(() => import('@pages/PrivacyPolicies'));
const Explore = lazy(() => import('@pages/Explore'));
const Book = lazy(() => import('@pages/Book'));
const Search = lazy(() => import('@pages/Search'));
const NewBook = lazy(() => import('@pages/NewBook'));
const Profile = lazy(() => import('@pages/profile/Profile'));

export function Private({ children }: { children: React.ReactNode }) {
const { currentUser, loading } = useAuth();
const location = useLocation();

if (loading) {
return <SkeletonAllBooks />;
}

if (currentUser && location.pathname === '/login') {
return <Navigate to='/explore' />;
}

return <>{children}</>;
}

const routes = createBrowserRouter([
{
path: '/',
element: <Layout />,
children: [
{
index: true,
element: (
// <Private>
<Home />
// </Private>
),
element: <Home />,
},
{
path: '/explore',
Expand All @@ -64,17 +42,9 @@ const routes = createBrowserRouter([
path: '/privacy-policies',
element: <PrivacyPolicies />,
},
{
path: '/register',
element: <Register />,
},
{
path: '/login',
element: (
// <Private>
<Login />
// </Private>
),
element: <Login />,
},
{
path: '/books',
Expand Down

1 comment on commit 8add472

@vercel
Copy link

@vercel vercel bot commented on 8add472 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-franqsanz.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.