-
-
-
-
404 Not Found
-
- Link invalid or expired.
-
-
-
- Go Home
-
-
+
+ );
+ }
+
+ if (needsAuth) {
+ return (
+
+
+
+
+ Protected Link
+
+
+ Enter credentials to continue
+
+
+ {authError && (
+
+ {authError}
+
+ )}
+
+
);
}
return (
-
- Redirecting...
-
+
+ Redirecting...
+
);
}
diff --git a/frontend/src/pages/Register.tsx b/frontend/src/pages/Register.tsx
new file mode 100644
index 0000000..651b230
--- /dev/null
+++ b/frontend/src/pages/Register.tsx
@@ -0,0 +1,98 @@
+import { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
+import { useAuth } from '../context/AuthContext';
+
+export default function Register() {
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+ const [confirm, setConfirm] = useState('');
+ const [error, setError] = useState('');
+ const [loading, setLoading] = useState(false);
+ const { register, user } = useAuth();
+ const navigate = useNavigate();
+
+ if (user) {
+ navigate('/links');
+ return null;
+ }
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ setError('');
+
+ if (password !== confirm) {
+ setError('Passwords do not match');
+ return;
+ }
+
+ setLoading(true);
+ try {
+ await register(username, password);
+ navigate('/links');
+ } catch (err: any) {
+ setError(err.response?.data?.message || 'Registration failed');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+
+
+
+ Register
+
+
+
+ {error && (
+
+ {error}
+
+ )}
+
+ Already have an account?{' '}
+
+ Login
+
+
+
+
+
+ );
+}