Spaces:
Sleeping
Sleeping
FauziIsyrinApridal commited on
Commit ·
7ca96c1
1
Parent(s): 887e353
..
Browse files- app/(auth)/reset-password/page.tsx +2 -2
- middleware.ts +4 -2
- utils/signIn.ts +2 -2
app/(auth)/reset-password/page.tsx
CHANGED
|
@@ -25,8 +25,8 @@ export default function ResetPasswordPage() {
|
|
| 25 |
const role = data?.user?.user_metadata?.role;
|
| 26 |
if (role !== "admin") {
|
| 27 |
await supabase.auth.signOut();
|
| 28 |
-
//
|
| 29 |
-
window.location.href = "
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
}
|
|
|
|
| 25 |
const role = data?.user?.user_metadata?.role;
|
| 26 |
if (role !== "admin") {
|
| 27 |
await supabase.auth.signOut();
|
| 28 |
+
// Keep inside admin app
|
| 29 |
+
window.location.href = "/login?error=not_admin";
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
}
|
middleware.ts
CHANGED
|
@@ -39,8 +39,10 @@ export async function middleware(request: NextRequest) {
|
|
| 39 |
const role = data?.user?.user_metadata?.role;
|
| 40 |
|
| 41 |
if (!data?.user || role !== "admin") {
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
return response;
|
|
|
|
| 39 |
const role = data?.user?.user_metadata?.role;
|
| 40 |
|
| 41 |
if (!data?.user || role !== "admin") {
|
| 42 |
+
const url = request.nextUrl.clone();
|
| 43 |
+
url.pathname = "/login";
|
| 44 |
+
url.searchParams.set("error", "not_admin");
|
| 45 |
+
return NextResponse.redirect(url);
|
| 46 |
}
|
| 47 |
|
| 48 |
return response;
|
utils/signIn.ts
CHANGED
|
@@ -35,8 +35,8 @@ export async function login(email: string, password: string): Promise<LoginResul
|
|
| 35 |
const role = user?.user_metadata?.role;
|
| 36 |
if (userErr || !user || role !== "admin") {
|
| 37 |
await supabase.auth.signOut();
|
| 38 |
-
//
|
| 39 |
-
redirect("
|
| 40 |
}
|
| 41 |
|
| 42 |
// Success and role OK: revalidate and redirect
|
|
|
|
| 35 |
const role = user?.user_metadata?.role;
|
| 36 |
if (userErr || !user || role !== "admin") {
|
| 37 |
await supabase.auth.signOut();
|
| 38 |
+
// Keep user inside admin app; show not-admin state on login
|
| 39 |
+
redirect("/login?error=not_admin");
|
| 40 |
}
|
| 41 |
|
| 42 |
// Success and role OK: revalidate and redirect
|