I want dynamic updates happening to the UI of a page when the user signs in. #31010
Unanswered
Abraham599
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using @/lib/supabase/server for storing the cookies but I want to dynamically change the text of the auth button from "Sign in" to "Sign out" (which is in nav-header.tsx) as the user successfully signs in. I tried onAuthStateChange but as it is for client-side mechanism, it only works well when the cookies are stored in client-side and not in server-side.
here is the nav-header.tsx which is global throughout the app
"use client"
import { supabase } from "@/lib/supabase/client"
import { useRouter } from "next/navigation"
import { Button } from "@/components/ui/button"
import Link from "next/link"
import {
NavigationMenu,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"
import { useEffect, useState } from "react"
import { LogOut, Loader2, Moon, Sun } from 'lucide-react'
import { useTheme } from "next-themes"
export function NavHeader() {
const router = useRouter()
const [isLoading, setIsLoading] = useState(true)
const [isAuthenticated, setIsAuthenticated] = useState(false)
const { theme, setTheme } = useTheme()
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
const handleSignOut = async () => {
try {
await supabase.auth.signOut()
router.push('/')
router.refresh()
} catch (error) {
console.error('Sign out failed:', error)
}
}
const toggleTheme = () => {
setTheme(theme === 'dark' ? 'light' : 'dark')
}
return (
InterviewPro
)
}
Beta Was this translation helpful? Give feedback.
All reactions