You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use @teamhanko/hanko-elements to easily manage user logouts. Below, we make a logout button component that you can use anywhere.
import{useState,useEffect}from"react";import{useRouter}from"next/router";import{Hanko}from"@teamhanko/hanko-elements";consthankoApi=process.env.NEXT_PUBLIC_HANKO_API_URL;exportfunctionLogoutBtn(){constrouter=useRouter();const[hanko,setHanko]=useState<Hanko>();useEffect(()=>{import("@teamhanko/hanko-elements").then(({ Hanko })=>setHanko(newHanko(hankoApi??"")));},[]);constlogout=async()=>{try{awaithanko?.user.logout();router.push("/login");router.refresh();<----------errorreturn;}catch(error){console.error("Error during logout:",error);}};return<buttononClick={logout}>Logout</button>;}
The docs mention router.refresh() but that method doesn't exist on the Next Router object. I think the author of this meant to use router.reload()
The text was updated successfully, but these errors were encountered:
Hey @Jemeni11 thanks for the pr. Yeah you're right, but router.refresh is available in nextjs app directory. And you seem to have replace the router.refresh in both the codes(app directory and pages directory). can you please fix that. Thanks!
* Update next.mdx
Fixes#18
* Update next.mdx
Changed all occurrences of `router.refresh()` to `router.reload()`
* Update next.mdx
Reversed the change to the App directory example
Path: /quickstarts/fullstack/next
Next JS - Implement logout functionality
Pages Directory
You can use
@teamhanko/hanko-elements
to easily manage user logouts. Below, we make a logout button component that you can use anywhere.The docs mention
router.refresh()
but that method doesn't exist on the Next Router object. I think the author of this meant to userouter.reload()
The text was updated successfully, but these errors were encountered: