Skip to content

Commit 709d6a4

Browse files
committed
feat(auth): Enhance Access Denied alert with Toast and improved UI
1 parent 4c09d7b commit 709d6a4

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/app/auth/login/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { useState } from "react";
44
import { signIn } from "@/lib/firebase/auth";
55
import { useRouter } from "next/navigation";
66
import Link from "next/link";
7-
import { Lock, Mail, Eye, EyeOff } from "lucide-react";
7+
import { Lock, Mail, Eye, EyeOff, AlertTriangle } from "lucide-react";
88
import { CONFIG } from "@/lib/config";
9+
import { useToast } from "@/context/ToastContext";
910

1011
export default function LoginPage() {
1112
const [email, setEmail] = useState("");
@@ -14,6 +15,7 @@ export default function LoginPage() {
1415
const [error, setError] = useState("");
1516
const [loading, setLoading] = useState(false);
1617
const router = useRouter();
18+
const { addToast } = useToast();
1719

1820
const handleLogin = async (e: React.FormEvent) => {
1921
e.preventDefault();
@@ -25,7 +27,9 @@ export default function LoginPage() {
2527
router.push("/dashboard");
2628
} catch (err: any) {
2729
if (err.message === "ACCESS_DENIED") {
28-
setError("Access Denied. You are not authorized to access this application.");
30+
const msg = "Access Denied. Authorization required.";
31+
setError(msg);
32+
addToast(msg, "error");
2933
} else {
3034
setError("Invalid email or password.");
3135
}
@@ -48,8 +52,13 @@ export default function LoginPage() {
4852
padding: "0.75rem",
4953
borderRadius: "0.5rem",
5054
marginBottom: "1rem",
51-
fontSize: "0.9rem"
55+
fontSize: "0.9rem",
56+
display: "flex",
57+
alignItems: "center",
58+
gap: "0.5rem",
59+
border: "1px solid #f87171"
5260
}}>
61+
<AlertTriangle size={18} />
5362
{error}
5463
</div>
5564
)}

src/app/auth/signup/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { useState } from "react";
44
import { signUp } from "@/lib/firebase/auth";
55
import { useRouter } from "next/navigation";
66
import Link from "next/link";
7-
import { Lock, Mail, UserPlus, User, Eye, EyeOff } from "lucide-react";
7+
import { Lock, Mail, UserPlus, User, Eye, EyeOff, AlertTriangle } from "lucide-react";
88
import { CONFIG, validatePassword } from "@/lib/config";
9+
import { useToast } from "@/context/ToastContext";
910

1011
export default function SignupPage() {
1112
const [name, setName] = useState("");
@@ -16,6 +17,7 @@ export default function SignupPage() {
1617
const [loading, setLoading] = useState(false);
1718
const [success, setSuccess] = useState(false);
1819
const router = useRouter();
20+
const { addToast } = useToast();
1921

2022
const handleSignup = async (e: React.FormEvent) => {
2123
e.preventDefault();
@@ -35,7 +37,9 @@ export default function SignupPage() {
3537
setSuccess(true);
3638
} catch (err: any) {
3739
if (err.message === "ACCESS_DENIED") {
38-
setError("Access Denied. You are not authorized to access this application.");
40+
const msg = "Access Denied. Authorization required.";
41+
setError(msg);
42+
addToast(msg, "error");
3943
} else if (err.code === 'auth/email-already-in-use') {
4044
setError("Email already in use.");
4145
} else if (err.code === 'auth/weak-password') {
@@ -86,8 +90,13 @@ export default function SignupPage() {
8690
padding: "0.75rem",
8791
borderRadius: "0.5rem",
8892
marginBottom: "1rem",
89-
fontSize: "0.9rem"
93+
fontSize: "0.9rem",
94+
display: "flex",
95+
alignItems: "center",
96+
gap: "0.5rem",
97+
border: "1px solid #f87171"
9098
}}>
99+
<AlertTriangle size={18} />
91100
{error}
92101
</div>
93102
)}

0 commit comments

Comments
 (0)