Skip to content

Commit

Permalink
Create private route guard
Browse files Browse the repository at this point in the history
Consume verify token api and refator its implementation to middleware
  • Loading branch information
Fingertips18 committed Sep 13, 2024
1 parent 84b6981 commit 8d42826
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 106 deletions.
64 changes: 64 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
},
"dependencies": {
"@tanstack/react-query": "^5.56.1",
"js-cookie": "^3.0.5",
"lucide-react": "^0.440.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.2",
"react-tooltip": "^5.28.0",
"sonner": "^1.5.0"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/js-cookie": "^3.0.6",
"@types/node": "^22.5.4",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand Down
7 changes: 5 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Route, Routes } from "react-router-dom";

import ProtectedGuard from "@/guards/protected-guard";
import { AppRoutes } from "@/constants/routes";
import SignUpPage from "@/pages/sign-up/page";
import SignInPage from "@/pages/sign-in/page";
import RootPage from "@/pages/root/page";

function App() {
return (
<main className="h-dvh overflow-x-hidden">
<main className="h-dvh overflow-x-hidden overflow-y-auto">
<Routes>
<Route path={AppRoutes.Root} element={<RootPage />} />
<Route element={<ProtectedGuard />}>
<Route path={AppRoutes.Root} element={<RootPage />} />
</Route>
<Route path={AppRoutes.SignUp} element={<SignUpPage />} />
<Route path={AppRoutes.SignIn} element={<SignInPage />} />
</Routes>
Expand Down
25 changes: 22 additions & 3 deletions client/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
useState,
} from "react";
import { Eye, EyeOff, Info, LucideProps } from "lucide-react";
import { Tooltip } from "react-tooltip";

interface InputProps {
name?: string;
label: string;
tooltip: string;
placeholder: string;
type: React.HTMLInputTypeAttribute | undefined;
autoComplete: React.HTMLInputAutoCompleteAttribute | undefined;
Expand All @@ -18,18 +20,21 @@ interface InputProps {
disabled?: boolean;
validation: (value: string) => boolean;
required?: boolean;
maxLength?: number;
}

const Input = ({
name,
label,
tooltip,
placeholder,
type,
autoComplete,
suffixIcon: SuffixIcon,
disabled,
validation,
required,
maxLength,
}: InputProps) => {
const [value, setValue] = useState("");
const [obscure, setObscure] = useState(true);
Expand All @@ -51,7 +56,20 @@ const Input = ({
>
{label}
</label>
<Info size={16} className="text-primary" />
<Info
size={16}
className="text-primary cursor-help"
data-tooltip-id={label}
data-tooltip-content={tooltip}
/>
<Tooltip
id={label}
style={{
backgroundColor: "rgb(var(--primary))",
color: "rgb(var(--foreground))",
fontWeight: "bold",
}}
/>
</div>
<div className="relative flex-center">
<input
Expand All @@ -64,7 +82,8 @@ const Input = ({
name={name?.toLowerCase() ?? label.toLowerCase()}
disabled={disabled}
required={required}
className={`w-full lg:w-[400px] bg-background p-2.5 rounded-lg outline-none border ring-1 focus:ring-2 transition-all placeholder-foreground/50
maxLength={maxLength}
className={`w-full md:w-[400px] bg-background p-2.5 rounded-lg outline-none border ring-1 focus:ring-2 transition-all placeholder-foreground/50
px-11 disabled:bg-opacity-25 disabled:border-primary/25 disabled:text-foreground/50 disabled:pointer-events-none
${
hasInput
Expand All @@ -81,7 +100,7 @@ const Input = ({
<button
type="button"
onClick={() => setObscure(!obscure)}
className="absolute inset-y-0 right-0 flex-center pr-3"
className="absolute inset-y-0 right-0 flex-center pr-3 active:scale-90 transition hover:drop-shadow-primary-glow"
>
{obscure ? (
<EyeOff size={24} className="text-primary" />
Expand Down
16 changes: 16 additions & 0 deletions client/src/components/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Loader2 } from "lucide-react";

const Loading = () => {
return (
<section className="flex-center bg-black/15 w-full h-full absolute z-50">
<div className="p-4 rounded-full border border-primary/80 bg-primary/15 drop-shadow-primary-glow backdrop-blur-lg ">
<Loader2
className="text-primary animate-spin duration-200 transition-transform"
size={32}
/>
</div>
</section>
);
};

export { Loading };
8 changes: 4 additions & 4 deletions client/src/components/or.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const Or = () => {
return (
<div className="flex-between gap-x-2 w-[400px]">
<span className="h-px w-full flex-1 bg-foreground/40" />
<p className="text-lg font-semibold text-foreground/40">Or</p>
<span className="h-px flex-1 bg-foreground/40" />
<div className="flex-between gap-x-2 w-full md:w-[400px] px-6 lg:px-0">
<span className="h-px w-full flex-1 bg-foreground/40 rounded-full" />
<p className="text-sm lg:text-lg font-semibold text-foreground/40">Or</p>
<span className="h-px flex-1 bg-foreground/40 rounded-full" />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/switch-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface SwitchAuthProps {

const SwitchAuth = ({ label, tag, href }: SwitchAuthProps) => {
return (
<div className="p-4 w-[400px] rounded-md border border-secondary/50 bg-secondary/15 drop-shadow-2xl flex-center gap-x-2">
<div className="p-4 w-full md:w-[400px] text-sm lg:text-base rounded-md border border-secondary/50 bg-secondary/15 drop-shadow-2xl flex-center gap-x-2">
<p className="font-medium">{label}</p>
<Link
to={href}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/text-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const TextButton = ({
type={type}
onClick={onClick}
disabled={disabled || loading}
className="w-full h-10 p-6 rounded-lg bg-accent transition-all hover:drop-shadow-accent-glow border-2 border-transparent hover:border-white/50
flex-center font-bold text-lg active:scale-90 disabled:bg-accent/50 disabled:text-foreground/50 disabled:pointer-events-none"
className="w-full h-10 p-4 lg:p-6 rounded-lg bg-accent transition-all hover:drop-shadow-accent-glow border-2 border-transparent hover:border-white/50
flex-center font-bold lg:text-lg active:scale-90 disabled:bg-accent/50 disabled:text-foreground/50 disabled:pointer-events-none"
>
{loading ? <Loader2 className="animate-spin duration-200" /> : label}
</button>
Expand Down
17 changes: 17 additions & 0 deletions client/src/constants/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,74 @@ export const SIGNUPINPUTS = [
{
name: "username",
label: "Username",
tooltip: "Choose a username between 3 and 20 characters.",
placeholder: "e.g. john doe",
type: "text",
autoComplete: "username",
suffixIcon: User,
validation: ValidateUsername,
maxLength: 20,
},
{
name: "email",
label: "Email Address",
tooltip:
"Please enter a valid email address. Ensure it includes an '@' symbol and a domain name.",
placeholder: "e.g. [email protected]",
type: "email",
autoComplete: "email",
suffixIcon: Mail,
validation: ValidateEmail,
maxLength: 254,
},
{
name: "password",
label: "Password",
tooltip:
"Create a strong password with at least 8 characters. Include a mix of uppercase letters, lowercase letters, numbers, and special characters for better security.",
placeholder: "e.g. m#P52s@ap$V",
type: "password",
autoComplete: "new-password",
suffixIcon: Lock,
validation: ValidatePassword,
maxLength: 128,
},
{
label: "Confirm Password",
tooltip:
"Re-enter your password to confirm it matches the one you typed above. Ensure both passwords are identical.",
placeholder: "e.g. m#P52s@ap$V",
type: "password",
autoComplete: "new-password",
suffixIcon: Lock,
validation: ValidateConfirmPassword,
maxLength: 128,
},
];

export const SIGNININPUTS = [
{
name: "email",
label: "Email Address",
tooltip:
"Please enter a valid email address. Ensure it includes an '@' symbol and a domain name.",
placeholder: "e.g. [email protected]",
type: "email",
autoComplete: "email",
suffixIcon: Mail,
validation: ValidateEmail,
maxLength: 254,
},
{
name: "password",
label: "Password",
tooltip:
"Create a strong password with at least 8 characters. Include a mix of uppercase letters, lowercase letters, numbers, and special characters for better security.",
placeholder: "e.g. m#P52s@ap$V",
type: "password",
autoComplete: "new-password",
suffixIcon: Lock,
validation: ValidatePassword,
maxLength: 128,
},
];
1 change: 1 addition & 0 deletions client/src/constants/keys.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const SIGNUPKEY = "sign-up";
export const SIGNINKEY = "sign-in";
export const SIGNOUTKEY = "sign-out";
export const VERIFYTOKENKEY = "verify-token";
1 change: 1 addition & 0 deletions client/src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum AppRoutes {
ForgotPassword = "/forgot-password",
ResetPassword = "/reset-password",
VerifyEmail = "/verify-email",
VerifyToken = "/verify-token",
}
Loading

0 comments on commit 8d42826

Please sign in to comment.