That is by design. Suppose the user opened multiple browser tabs of your application. And, they login, in one of the tab. Then the other tab will not have the login state. It is confusing and does not feel reactive. So, instead the useSWR hook in Next.js calls the /api/user/ route on tab refocus, connection reconnect etc.
Similar case is when, suppose the user updated their name in one tab, then the old name will be visible in another tab. useSWR also revalidates/re-fetches stale data.
If you want, you can disable this feature. https://swr.vercel.app/docs/revalidation
In hooks/auth.js file update the useSWR to:
const { data: user, error, revalidate } = useSWR('/api/user', () =>
axios
.get('/api/user')
.then(res => res.data)
.catch(error => {
if (error.response.status !== 409) throw error
router.push('/verify-email')
}), {
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false
})
The user data will only be revalidated when you call revalidate() like in register, login functions.