#Is "session" repeating in network tab normal?

35 messages · Page 1 of 1 (latest)

junior timber
#

I get like 10 of these in 30 secs
Is this normal?

unreal voidBOT
#

🔎 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)

junior timber
#

Btw im using nextjs

zinc nova
tender copperBOT
# junior timber I get like 10 of these in 30 secs Is this normal?
Please add more information to your question

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.

junior timber
# zinc nova have you added a dependency array to `useEffect`
  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

zinc nova
#

or some other useEffect, which triggers the request

junior timber
#

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

zinc nova
#

I'd be concerned if that happens

zinc nova
junior timber
zinc nova
#

which file is this, like page or layout

junior timber
#

and all the sub directories of it

zinc nova
junior timber
#

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": ""
}
zinc nova
junior timber
#

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

zinc nova
#

Why don't you get the session in server action instead?

junior timber
#

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>
zinc nova
#

are you using any authentication package?

junior timber
#

And the providers.tsx :

'use client'

import { SessionProvider } from "next-auth/react"

export const Providers = ({ children }: { children: React.ReactNode }) => {
  return (
    <SessionProvider>
      {children}
    </SessionProvider>
  )
}

junior timber
junior timber