0

I am trying to use next-auth with the patreon api. Logging in & out works fine, but I now want to also save the users tier somewhere - the question is where? I was thinking of putting it directly on the jwt via the jwt callback, or maybe in the session via the session callback.

I have tried adding it to the session, but it seems to really slow down login:

    async session({ session, token, user }) {
        session.access_token = token.access_token;

        let tier = await getUserTier({ access_token: token.access_token });
        session.tier = tier;

        return session;
    }

It also feels inefficient fetching this data every single time the session callback is called - which seems to be a lot. Is there any way to speed up this process of checking the tier? Is there any convention over where I could save the tier?

antonwilhelm
  • 5,768
  • 4
  • 19
  • 45

1 Answers1

0

Its slowing down the process naturally because, additionaly to the network traffic that is neccesary by default, you have to wait for your getUserTier request.

I think you have 2 options:

  1. Saving the user Tier in the User table of the database directly, then you should have access to it through one of the callback parameters.

  2. Not include the tier in the session at all, but fetching it in your client code only at the time you really need it.

I think i would go with the second option because there is no real need to include this information in the session. If your argument is that need that information everywhere in your app, you can still do the request somewhere central - like in a Layout component - and then provide the info via Context or Redux Store or similar(depends on what you use in your app already)

Laurenz Honauer
  • 254
  • 1
  • 12