mirror of
https://github.com/ershisan99/todolist_next.git
synced 2026-01-21 05:12:09 +00:00
initial commit, login page
This commit is contained in:
29
src/components/AuthRedirect.tsx
Normal file
29
src/components/AuthRedirect.tsx
Normal 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
17
src/components/Button.tsx
Normal 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
17
src/components/Input.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
7
src/components/loader.tsx
Normal file
7
src/components/loader.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user