initial commit, login page

This commit is contained in:
2022-11-19 17:30:58 +01:00
commit 41b49d6306
35 changed files with 4674 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import type { FC, ReactNode } from "react";
import { useEffect } from "react";
import { useRouter } from "next/router";
import { useMeQuery } from "../services/hooks";
import { Loader } from "./loader";
export const AuthRedirect: FC<{ children: ReactNode }> = ({ children }) => {
const router = useRouter();
const { data: user, isLoading, isError } = useMeQuery();
console.log(user);
const isAuthPage = router.pathname === "/login";
useEffect(() => {
console.log("here");
if (!isLoading && !user && !isAuthPage) {
console.log("here");
router.push("/login");
}
}, [user, isError, isLoading, isAuthPage, router]);
if (isLoading || (!user && !isAuthPage)) {
return (
<div className={"h-screen"}>
<Loader />
</div>
);
}
return <>{children}</>;
};

17
src/components/Button.tsx Normal file
View File

@@ -0,0 +1,17 @@
import type { ButtonHTMLAttributes, DetailedHTMLProps, FC } from "react";
type Props = DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>;
export const Button: FC<Props> = ({ className, ...rest }) => {
return (
<div>
<button
className={`rounded-md border border-gray-300 bg-sky-700 px-4 py-2 text-white focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-600 ${className}`}
{...rest}
/>
</div>
);
};

17
src/components/Input.tsx Normal file
View File

@@ -0,0 +1,17 @@
import type { DetailedHTMLProps, FC, InputHTMLAttributes } from "react";
type Props = DetailedHTMLProps<
InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
>;
export const Input: FC<Props> = ({ className, ...rest }) => {
return (
<div>
<input
className={` w-full rounded-md border border-gray-300 px-4 py-2 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-600 ${className}`}
{...rest}
/>
</div>
);
};

View File

@@ -0,0 +1,7 @@
export const Loader = () => {
return (
<div className={"flex h-full w-full items-center justify-center"}>
<span className="loader"></span>
</div>
);
};