Move information from one webpage to a different page

After developing a site using NextJs, I successfully integrated Discord login functionality and was able to retrieve the user's guilds in the oauth file.

Now, I am looking to send this list of guilds (in JSON format) to my dashboard page.

In the oauth.tsx file:

export default async (req: NextApiRequest, res: NextApiResponse) => {
...
  const guildsuser = await fetch("http://discord.com/api/users/@me/guilds", {
    headers: { Authorization: `${token_type} ${access_token}` },
  });
  const guilds = guildsuser.json();
}

The guilds constant contains the data that I want to pass to the dashboard page for display.

Answer №1

Fortunately, all you need is to add a single line of code to return the guilds to the front-end dashboard.

export default async (req: NextApiRequest, res: NextApiResponse) => {
...
  const guildsuser = await fetch("http://discord.com/api/users/@me/guilds", {
    headers: { Authorization: `${token_type} ${access_token}` },
  });
  const guilds = await guildsuser.json();
  res.status(200).json({ guilds })
}

Please remember to include await before guilduser.json() like this

You can explore more options for sending responses in the documentation:

https://nextjs.org/docs/api-routes/response-helpers

Answer №2

After careful consideration, I have decided to store the information using cookies.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to optimize images in Next.js standalone mood?

I am currently working on my next build with standalone output. I came across this helpful answer on Stack Overflow- How to deploy NextJs (SSR) using the "Output File Tracing" feature to Azure App Service? After setting everything up, I started my server ...

AngularJS redirection to a different state by utilizing a URL

When I need to direct a user to a specific state, typically I would use the following code: $state.go('state_name'); $state.transitionTo('state_name'); This method usually takes users to /state_name. However, there is one particular s ...

Master the art of manipulating tags in Django templates using JavaScript

In my Django quiz app, there are two main components. The first part involves displaying 10 sentences with corresponding audio to help with memorization, one per page. The second part consists of asking questions based on the same set of sentences. I initi ...

Updating code to insert elements into an array/data structure using Javascript

Hey everyone, I'm new to Javascript and I'm trying to make a change to some existing code. Instead of just returning the count of elements, I want to add each of the specified elements to an array or list. Here is the original code from a Seleni ...

Azure OpenAPI: Streaming responses function properly on local host, yet encounter difficulty on Azure Web App

Utilizing the Fetch API, I'm fetching a streamed response from my API endpoint. Testing this on my local machine shows that the response functions correctly. However, upon deploying the application to an Azure Web App, the streamed response is no long ...

Using a JavaScript function inside a loop without the need for a click event

I have successfully created a slideshow, but I am facing an issue with looping it continuously. Currently, I have implemented a click event to restart the script, but I want it to loop without the need for any interaction. window.CP.exitedLoop(0);functio ...

Integrating additional JavaScript into an Ionic 2 project

Imagine we have a foo.js file containing a variable, function, and class that are not yet part of the project. Now suppose we want to access these elements in our home.ts method or make them globally available for use within a home.ts method. How can this ...

Updating an SVG after dynamically adding a group with javascript: a step-by-step guide

Currently, I am working on a circuit builder project using SVG for the components. In my HTML structure, I have an empty SVG tag that is scaled to full width and height. When I drag components from the toolbar into the canvas (screen), my JavaScript functi ...

Issues with AngularJS functionality – $route.reload() not functioning as expected

I'm attempting to refresh the page using $route.reload(): var App = angular.module("App", ["ngRoute"]); var idx = 0; App.controller("List", function ($scope, $route) { $scope.changeWallet = function (index) { idx = index; $r ...

Utilizing the @mailchimp/mailchimp_marketing Package in Conjunction with the Next.js 14 App Router API

I am currently working on setting up a signup form for a Mailchimp Newsletter within my Next.js 14 Typescript Application using the new App router. After installing the @mailchimp/mailchimp_marketing package via npm, I have encountered difficulties in pin ...

What is the best way to manage numerous asynchronous post requests in AngularJS?

$scope.savekbentry = function (value) { console.log('save clicked'); console.log(value); console.log($scope.kbentry.kbname); $scope.kbentry.mode = value; var kbname = $scope.kbentry.kbname; var kbd ...

Forcing a property binding update in Angular 2

Take a look at this particular component import {Component} from 'angular2/core' @Component({ selector: 'my-app', providers: [], template: ` <div> <h3>Input with two decimals</h3> <input type ...

Submitting an extremely large string to an Express server using JS

How can a large String be efficiently sent to a Node.js Express server? On my webpage, I am using Codemirror to load files from an Express server into the editor. However, what is the most effective method for sending "the file" (which is actually a bi ...

Newly included JavaScript file displays on view page, but triggers a 404 error when attempting to open

Once I implemented the following code in the child theme's function.php file: add_action('wp_enqueue_scripts', 'js_files'); function js_files() { wp_register_script('ajax_call_mkto', get_template_directory_uri() . ' ...

Creating Web Components using JavaScript on the fly

I tried to create web components directly from JavaScript, but I encountered an issue where the public constructor could not be found. Here's a basic example to illustrate the situation: The HTML Template: <polymer-element name="wc-foo" construct ...

Node.js request body is not returning any data

UPDATE: @LawrenceCherone was able to solve the issue, it's (req, res, next) not (err, res, req) I'm in the process of building a MERN app (Mongo, Express, React, Node). I have some routes that are functioning well and fetching data from MongoDB. ...

Extracting public data from social media profiles as displayed in Smartr

Is there any pre-existing API or reference material available for achieving this task? I am interested in accessing public social data without the need for users to manually link their accounts to our site. ...

Using JavaScript and HTML, create a click event that triggers a drop-down text

Can anyone help me with creating a dropdown feature using JavaScript, HTML, and CSS? I want to be able to click on the name of a project and have information about that project show up. Any suggestions on how I can achieve this? Thanks in advance! ...

Encountering an issue when using the Google authentication provider with Next.js version 13

I am currently working on integrating next-auth with the Google provider and Prisma in my Next.js application, but I encountered the following error: Error: Detected default export in '/MyProject/foodbrain/app/api/auth/[...nextauth]/route.ts'. Pl ...

Looping through an object with AngularJS's ng-repeat

Upon receiving an object as the scope, which has the following structure: The controller function is defined as follows: module.controller('ActiveController', ['$scope','$http', function($scope, $http) { $h ...