#Is "session" repeating in network tab normal?
35 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
Btw im using nextjs
have you added a dependency array to useEffect
Your question currently does not have sufficient information for people to be able to help. Please add more information to help us help you, for example: relevant code snippets, a reproduction repository, and/or more detailed error messages. See more info on how to ask a good question in https://discord.com/channels/752553802359505017/1138338531983491154 and #welcome message.
useEffect(() => {
if (session?.accessToken) {
const fetchUserInfo = async () => {
try {
const response = await getUserInfo(session.accessToken)
const data = await response.data
setFirstName(data.first_name || '')
setLastName(data.last_name || '')
setEmail(data.email || 'Not set')
setPhone(data.phone || '')
} catch (err) {
console.error('Failed to fetch user info:', err)
setError('Failed to fetch user info')
}
}
fetchUserInfo()
}
}, [session?.accessToken])
I have multiple useEffects btw
accessToken might be getting updated from time to time
or some other useEffect, which triggers the request
So should I be concerned about it or just let it stay?
By the way a new session request comes when I switch between pages or tabs or have any interaction with the website
They don't come on their own when I don't touch the screen or switching between apps
I'd be concerned if that happens
are you running useEffect on every page
The only useEffect related to session in my whole app
which file is this, like page or layout
app/dashboard/page.tsx
and all the sub directories of it
so in each page.tsx?
The session have this data :
{
"user": {
"email": null,
"id": 27,
"phone": "09021234567",
"firstName": null,
"lastName": null,
"role": "customer",
"isAdmin": false
},
"expires": "2024-12-26T21:21:41.621Z",
"accessToken": "",
"refreshToken": ""
}
?
Only where it's needed
But I see it on all the protected pages
Oh wait sorry
When I'm logged in
I get that session in all of the pages
Everywhere
Even unprotected parts
Why don't you get the session in server action instead?
And my main layout.tsx is wrapped in SessionProvider btw
<html lang="en" dir="ltr">
<body className={`${Diroz.className} antialiased`}>
<Providers>
<Suspense fallback={<Loading />}>
<Navbar />
{children}
<Footer />
</Suspense>
</Providers>
</body>
</html>
are you using any authentication package?
And the providers.tsx :
'use client'
import { SessionProvider } from "next-auth/react"
export const Providers = ({ children }: { children: React.ReactNode }) => {
return (
<SessionProvider>
{children}
</SessionProvider>
)
}
Yeah nextauth
Like how? it requires the app to be wrapped inside SessionProvider