diff --git a/client/src/components/AuthForm.tsx b/client/src/components/AuthForm.tsx index 2cffe97..0184c12 100644 --- a/client/src/components/AuthForm.tsx +++ b/client/src/components/AuthForm.tsx @@ -32,11 +32,15 @@ const AuthForm: React.FC = () => { const [password, setPassword] = useState(""); const [isLogin, setIsLogin] = useState(true); + //added + const [showPassword, setShowPassword] = useState(false); + const [login] = useMutation(LOGIN); const [register] = useMutation(REGISTER); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + try { const mutation = isLogin ? login : register; const result = await mutation({ variables: { username, password } }); @@ -72,10 +76,8 @@ const AuthForm: React.FC = () => { {/* Form */} -
+ { placeholder="Username" onChange={(e) => setUsername(e.target.value)} /> +
setPassword(e.target.value)} /> - - + {/* setPassword(e.target.value)} + /> */} + + + + + + ) : ( + + + + + + )} +
- + + + + {/* Toggle Login/Register */} + + + ); }; diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index 9c79298..2185e7c 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -1,5 +1,6 @@ import jwt from "jsonwebtoken"; import dotenv from "dotenv"; + dotenv.config(); const secret = process.env.JWT_SECRET!; @@ -9,7 +10,9 @@ export function signToken(user: { _id: string; username: string }) { return jwt.sign({ data: user }, secret, { expiresIn: expiration }); } + export function authMiddleware({ req }: any) { + let token = req.headers.authorization || ""; if (token.startsWith("Bearer ")) {