title: Discord.js Oauth2 with passport.js
body: <p>I'm having some bad days trying figuring out how to use the <code>refresh_token</code> provided by the <code>passport-discord</code> strategy.</p>
  <p>I'm using <code>passport-oauth2-refresh</code> to obtain a new <code>accessToken</code> and <code>refreshToken</code>, but at this point i really don't know how to &quot;refresh&quot; the user object sent me by the passport-discord strategy</p>
  <p>This is the entire strategy logic</p>
  <pre><code>passport.serializeUser((user, done) =&gt; {
    done(null, user.id);
  });
  
  passport.deserializeUser(async (id, done) =&gt; {
    const user = await discordUser.findById(id);
    if (user) done(null, user);
  });
  
  const strat = new discordStrategy(
    {
      clientID: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      callbackURL: process.env.CLIENT_REDIRECT,
      scope: [&quot;identify&quot;, &quot;guilds&quot;],
    },
    async (accessToken, refreshToken, profile, done) =&gt; {
      try {
        let user = await discordUser.findOne({ discordId: profile.id });
        if (user) {
          discordUser.findOneAndUpdate(
            { discordId: profile.id },
            { guilds: profile.guilds, rtoken: refreshToken, atoken: accessToken },
  
            async (err) =&gt; {
              if (err) throw err;
              let newUser = await discordUser.findOne({ discordId: profile.id });
              done(null, newUser);
            }
          );
        } else {
          const newUser = await discordUser.create({
            discordId: profile.id,
            username: profile.username,
            discriminator: profile.discriminator,
            avatar: profile.avatar,
            guilds: profile.guilds,
            rtoken: refreshToken,
            atoken: accessToken,
          });
  
          const savedUser = await newUser.save();
  
          done(null, savedUser);
        }
      } catch (err) {
        console.log(err);
        done(err, null);
      }
    }
  );
  
  passport.use(&quot;discord&quot;, strat);
  refresh.use(&quot;discord&quot;, strat);
  </code></pre>
  <p>And this is the Express route that handle the login page</p>
  <pre><code>function isAuthorized(req, res, next) {
    if (req.user) {
      res.redirect(&quot;/&quot;);
    } else {
      next();
    }
  }
  
  router.get(&quot;/&quot;, passport.authenticate(&quot;discord&quot;));
  router.get(
    &quot;/redirect&quot;,
    isAuthorized,
    passport.authenticate(&quot;discord&quot;, {
      failureRedirect: &quot;/&quot;,
      successRedirect: &quot;/close&quot;,
    })
  );
  </code></pre>
  <p>I'm coding a web-dashboard that have to display all the guilds in witch the user have some special permissions...
  I need to update the user object each time the user navigate to the route <code>/guilds</code>, because he could have created a new guilds, or get promoted etc...</p>