Skip to content

What is the ideal way to use session data for API calls? #515

@ghoshnirmalya

Description

@ghoshnirmalya

Your question
I'm using the id from useSession like the following:

import { useSession } from 'next-auth/client'

Then, I'm importing the session value like the following:

const [ session, loading ] = useSession()

I'm using the value of the id from session. However, since a call to /api/auth/session is made whenever the browser is in focus, the state of my application reloads and it fetches data again as the parent component is re-rendered. See the screenshot below:

Kapture 2020-07-30 at 22 41 22

What are you trying to do
The whole application shouldn't be re-rendered. One possible solution could be that we can store the id from the session object in a cookie or localStorage and use it on every API call. However, I'd like to know if there is a better solution than this.

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsk how to do something or how something works

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions