Skip to content

Commit

Permalink
Better require login page (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston-Hsiao authored Nov 11, 2024
1 parent 80e6bb4 commit 55986fe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
5 changes: 4 additions & 1 deletion frontend/src/components/auth/AuthBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const AuthBlock: React.FC<AuthBlockProps> = ({ title, onClosed, signup }) => {
return (
<Card className="w-[400px] bg-gray-12 text-gray-12 rounded-lg">
<CardHeader>
<Header title={title} onClosed={onClosed} />
<Header
title={title ? title : signup ? "Signup" : "Login"}
onClosed={onClosed}
/>
</CardHeader>
<AuthBlockInner initialSignup={signup} />
</Card>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const AuthProvider = () => {
<div className="flex flex-col w-full">
<div className="flex justify-center items-center mb-4">
<div className="border-t border-gray-300 flex-grow mr-3"></div>
<span className="flex-shrink">OR</span>
<span className="text-white flex-shrink">OR</span>
<div className="border-t border-gray-300 flex-grow ml-3"></div>
</div>
<div className="flex items-center w-full gap-x-2">
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/components/auth/RequireAuthentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useNavigate } from "react-router-dom";

import AuthBlock from "@/components/auth/AuthBlock";
import Container from "@/components/ui/container";
import { useAuthentication } from "@/hooks/useAuth";

interface Props {
Expand All @@ -24,16 +25,16 @@ const RequireAuthentication = (props: Props) => {
return isAuthenticated ? (
<>{children}</>
) : (
<>
<div className="justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 z-50 outline-none focus:outline-none">
<div className="relative w-auto my-6 mx-auto max-w-3xl">
<div className="border-0 rounded-lg relative flex flex-col w-full bg-white outline-none focus:outline-none">
<AuthBlock onClosed={onClosed} />
</div>
<Container className="flex justify-center items-center max-w-xl">
<div className="flex flex-col justify-center items-center my-6">
<h2 className="text-gray-1 text-xl font-bold mb-4">
You must be logged in to view this page
</h2>
<div className="border-0 rounded-lg">
<AuthBlock onClosed={onClosed} />
</div>
</div>
<div className="opacity-25 fixed inset-0 z-40 bg-black"></div>
</>
</Container>
);
};

Expand Down
16 changes: 12 additions & 4 deletions frontend/src/components/ui/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { FaTimes } from "react-icons/fa";

import { cn } from "@/lib/utils";

interface HeaderProps {
title: string | React.ReactNode;
label?: string;
onClosed?: () => void;
className?: string;
}

const Header = ({ title, label, onClosed }: HeaderProps) => {
const Header = ({ title, label, onClosed, className }: HeaderProps) => {
return (
<div className="w-full flex flex-col items-center justify-center gap-y-4">
<h1 className="text-3xl font-semibold text-primary py-4">{title}</h1>
{label && <p className="text-muted-foreground text-s,">{label}</p>}
<div
className={cn(
"w-full flex flex-col items-center justify-center gap-y-4",
className,
)}
>
<h1 className="text-3xl font-semibold text-gray-1 py-4">{title}</h1>
{label && <p className="text-gray-3 text-sm">{label}</p>}
{onClosed && (
<button
onClick={onClosed}
Expand Down

0 comments on commit 55986fe

Please sign in to comment.