FauziIsyrinApridal commited on
Commit
7ca96c1
·
1 Parent(s): 887e353
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
- // Redirect non-admins to the public chatbot site
29
- window.location.href = "https://yozora721-pnp-chatbot-v1.hf.space/";
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
- // Redirect non-admins or unauthenticated to public chatbot site
43
- return NextResponse.redirect(new URL("https://yozora721-pnp-chatbot-v1.hf.space/"));
 
 
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
- // Redirect non-admin users to the chatbot app (public site)
39
- redirect("https://yozora721-pnp-chatbot-v1.hf.space/");
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