Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Who Me Too'd this topic

Unable to obtain a refresh token

I would like to get a refresh_token in Next.js, but no matter what I do, I cannot get one.

I would like to know how to do this.

Plan

Premium

Country

Japan

Device

PC

Operating System

Windows 10

 

My Question or Issue

The code is as follows

 

 

 

 

 

import { redirect_uri, client_id, client_secret, encode } from "@/module/env";

export default async function handle(req, res) {
  if (req.method === "POST") {
    const { code } = req.body;
    const url = "https://accounts.spotify.com/api/token";
    const params = new URLSearchParams();
    params.append("grant_type", "authorization_code");
    params.append("code", code);
    params.append("client_id", client_id || "");
    params.append("client_secret", client_secret || "");
    params.append("redirect_uri", redirect_uri || "/callback");
    const payload = {
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      body: params
    };
    const body = await fetch(url, payload);
    const response = await body.json();
    res.status(200).json(response);
  } else {
    res.status(405).json({ message: "We only support POST" }).end;
  }
}

export const config = {
  api: {
    externalResolver: true,
  },
};

 

 

 

 

 

 

Who Me Too'd this topic