From 387cfb0aa23b20d30aa28b9dbdc6e2462acbcfc4 Mon Sep 17 00:00:00 2001
From: talatops
Date: Wed, 4 Mar 2026 21:52:42 +0500
Subject: [PATCH] Refine role-aware login and theming
Made-with: Cursor
---
README.md | 16 +++++-
src/app/dashboard/layout.tsx | 4 +-
src/app/login/page.tsx | 101 +++++++++++++++++++++++++++++++++--
src/app/page.tsx | 22 ++++++--
src/app/supplier/layout.tsx | 5 +-
src/auth.ts | 44 ++++++++++++++-
6 files changed, 177 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 1322982..1d31a78 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,20 @@
## JUNO
-
+
+
+
-**Tech stack:** ⚛️ Next.js · 💙 TypeScript · 🐘 PostgreSQL · ☁️ AWS Bedrock · 📬 Gmail API · 🐳 Docker · 🔐 NextAuth
+**Tech stack**
+
+
+
+
+
+
+
+
+
+
Modern commerce and support infrastructure for Shopify‑based dropshipping businesses. 🚀
diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx
index eac7022..a586d0b 100644
--- a/src/app/dashboard/layout.tsx
+++ b/src/app/dashboard/layout.tsx
@@ -21,9 +21,9 @@ export default async function DashboardLayout({
if (session.user.role !== "VENDOR") {
if (session.user.role === "SUPPLIER") {
- redirect("/supplier")
+ redirect("/login?error=WrongPortal&role=SUPPLIER")
}
- redirect("/login")
+ redirect("/login?error=WrongRole")
}
const { prisma } = await import("@/lib/prisma")
diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx
index 41f1363..e2b94f1 100644
--- a/src/app/login/page.tsx
+++ b/src/app/login/page.tsx
@@ -1,21 +1,62 @@
"use client"
import { signIn } from "next-auth/react"
-import { useState } from "react"
-import { useRouter } from "next/navigation"
+import { useEffect, useState } from "react"
+import { useRouter, useSearchParams } from "next/navigation"
import { motion } from "framer-motion"
-import { Mail, Lock, Loader2, Shield } from "lucide-react"
+import { Mail, Lock, Loader2, Shield, ShoppingBag, Truck } from "lucide-react"
import Link from "next/link"
import Image from "next/image"
export default function LoginPage() {
const router = useRouter()
+ const searchParams = useSearchParams()
+ const initialRoleFromQuery =
+ searchParams.get("role")?.toUpperCase() === "SUPPLIER" ? "SUPPLIER" : "VENDOR"
+
const [loading, setLoading] = useState(false)
const [error, setError] = useState("")
const [requiresMFA, setRequiresMFA] = useState(false)
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [mfaCode, setMfaCode] = useState("")
+ const [role, setRole] = useState<"VENDOR" | "SUPPLIER">(initialRoleFromQuery)
+
+ const applyRoleCookie = (selectedRole: "VENDOR" | "SUPPLIER") => {
+ try {
+ document.cookie = `juno_login_role=${selectedRole}; path=/; max-age=600`
+ } catch {
+ // ignore cookie errors – server-side will just skip role enforcement
+ }
+ }
+
+ // Map Auth.js error codes from query string to friendly messages
+ useEffect(() => {
+ const errorCode = searchParams.get("error")
+ const existingRole = searchParams.get("existingRole")
+
+ if (errorCode === "SigninRoleMismatch") {
+ if (existingRole === "SUPPLIER") {
+ setError(
+ "This email is registered as a Supplier. Please choose the Supplier option or use another email."
+ )
+ setRole("SUPPLIER")
+ } else if (existingRole === "VENDOR") {
+ setError(
+ "This email is registered as a Vendor. Please choose the Vendor option or use another email."
+ )
+ setRole("VENDOR")
+ } else {
+ setError(
+ "This email is already registered with a different role. Please select the correct role or use another email."
+ )
+ }
+ } else if (errorCode === "WrongRole" || errorCode === "WrongPortal") {
+ setError(
+ "You tried to open a different portal with this account. Please sign in with the correct role or use a separate account."
+ )
+ }
+ }, [searchParams])
const handleCredentialsLogin = async (e: React.FormEvent) => {
e.preventDefault()
@@ -69,6 +110,9 @@ export default function LoginPage() {
return
}
+ // Ensure the selected role is visible to the auth callbacks
+ applyRoleCookie(role)
+
// If MFA was required and code provided, or MFA not required, proceed with NextAuth signIn
const res = await signIn("credentials", {
email: emailValue,
@@ -94,6 +138,7 @@ export default function LoginPage() {
}
const handleGoogleSignIn = () => {
+ applyRoleCookie(role)
signIn("google", { callbackUrl: "/onboarding" })
}
@@ -127,6 +172,56 @@ export default function LoginPage() {
+
+
+
+
+
+