fix: redirect after sign out

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
rever-tecnologia 2025-10-06 10:34:03 -03:00
parent 5d9cfde1d2
commit 82b00f206e
2 changed files with 9 additions and 1 deletions

View file

@ -2,7 +2,7 @@
import { type ReactNode, useMemo, useState } from "react" import { type ReactNode, useMemo, useState } from "react"
import Link from "next/link" import Link from "next/link"
import { usePathname } from "next/navigation" import { usePathname, useRouter } from "next/navigation"
import { LogOut, PlusCircle } from "lucide-react" import { LogOut, PlusCircle } from "lucide-react"
import { toast } from "sonner" import { toast } from "sonner"
@ -22,6 +22,7 @@ const navItems = [
export function PortalShell({ children }: PortalShellProps) { export function PortalShell({ children }: PortalShellProps) {
const pathname = usePathname() const pathname = usePathname()
const router = useRouter()
const { session, isCustomer } = useAuth() const { session, isCustomer } = useAuth()
const [isSigningOut, setIsSigningOut] = useState(false) const [isSigningOut, setIsSigningOut] = useState(false)
@ -41,9 +42,11 @@ export function PortalShell({ children }: PortalShellProps) {
try { try {
await signOut() await signOut()
toast.success("Sessão encerrada", { id: "portal-signout" }) toast.success("Sessão encerrada", { id: "portal-signout" })
router.replace("/login")
} catch (error) { } catch (error) {
console.error(error) console.error(error)
toast.error("Não foi possível encerrar a sessão", { id: "portal-signout" }) toast.error("Não foi possível encerrar a sessão", { id: "portal-signout" })
} finally {
setIsSigningOut(false) setIsSigningOut(false)
} }
} }

View file

@ -2,6 +2,7 @@
import { useMemo, useState } from "react" import { useMemo, useState } from "react"
import Link from "next/link" import Link from "next/link"
import { useRouter } from "next/navigation"
import { toast } from "sonner" import { toast } from "sonner"
import { Settings2, Share2, ShieldCheck, UserCog, UserPlus, Users2, Layers3 } from "lucide-react" import { Settings2, Share2, ShieldCheck, UserCog, UserPlus, Users2, Layers3 } from "lucide-react"
@ -87,6 +88,7 @@ const SETTINGS_ACTIONS: SettingsAction[] = [
export function SettingsContent() { export function SettingsContent() {
const { session, isAdmin, isStaff } = useAuth() const { session, isAdmin, isStaff } = useAuth()
const [isSigningOut, setIsSigningOut] = useState(false) const [isSigningOut, setIsSigningOut] = useState(false)
const router = useRouter()
const normalizedRole = session?.user.role?.toLowerCase() ?? "agent" const normalizedRole = session?.user.role?.toLowerCase() ?? "agent"
const roleLabel = ROLE_LABELS[normalizedRole] ?? "Agente" const roleLabel = ROLE_LABELS[normalizedRole] ?? "Agente"
@ -106,9 +108,12 @@ export function SettingsContent() {
setIsSigningOut(true) setIsSigningOut(true)
try { try {
await signOut() await signOut()
toast.success("Sessão encerrada")
router.replace("/login")
} catch (error) { } catch (error) {
console.error(error) console.error(error)
toast.error("Não foi possível encerrar a sessão.") toast.error("Não foi possível encerrar a sessão.")
} finally {
setIsSigningOut(false) setIsSigningOut(false)
} }
} }