- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
},
};
Solved! Go to Solution.
Labels:
- Labels:
-
Question
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page