Skip to content

Commit

Permalink
fix: authentication method
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Curtis committed Aug 16, 2024
1 parent 6f05e09 commit f7b2597
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAuth } from "../hooks/useAuth";
import { useAuth } from "../hooks";
import { LoadingWithSpinner } from "./LoadingWithSpinner";
import { ButtonAnimationDecorator } from "./decorators/ButtonAnimationDecorator";
import { ButtonAnimationDecorator } from "./decorators";
import { useState } from "react";
import { Link } from "react-router-dom";
import { Navbar, Button } from "react-bootstrap";
Expand Down Expand Up @@ -46,10 +46,10 @@ export const Header = (): JSX.Element => {
</h1>
</Link>
</Navbar.Brand>
{user && (
{user._id !== "" && (
<ButtonAnimationDecorator>
<Button
variant="dark"
variant="secondary"
onClick={handleSignOutClick}
disabled={isSigningOut}
className="w-100"
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
const { user, authenticate } = useAuth();

useEffect(() => {
if (!user) {
if (user._id === "") {
authenticate();
}
}, [user, authenticate]);

if (!user) {
if (user._id === "") {
return <Navigate to="/login" />;;
}

Expand Down
10 changes: 3 additions & 7 deletions src/components/PublicRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { useAuth } from "../hooks";
import { Navigate } from "react-router-dom";
import { useAuth } from "../hooks/useAuth";
import PropTypes from "prop-types";

export const PublicRoute = ({ children }) => {
export const PublicRoute = ({ children }: { children: React.ReactNode }) => {
const { user } = useAuth();

if (user) {
if (user._id !== "") {
return <Navigate to={`/${user._id}`}/>;
}

return children;
};

PublicRoute.propTypes = {
children: PropTypes.element,
};
2 changes: 1 addition & 1 deletion src/hooks/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const AuthContext = createContext({
user: DEFAULT_USER,
register: async (userData: UserRequest): Promise<UserResponse> =>
DEFAULT_USER_RESPONSE,
authenticate: async (userData: UserRequest): Promise<UserResponse> =>
authenticate: async (): Promise<UserResponse> =>
DEFAULT_USER_RESPONSE,
signIn: async (userData: UserRequest): Promise<UserResponse> =>
DEFAULT_USER_RESPONSE,
Expand Down

0 comments on commit f7b2597

Please sign in to comment.