PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

[FIXED] How to tell auth0 im authenticated in req.rest file

 September 02, 2022     auth0, authentication, rest     No comments   

Issue

So I want to make a post request to my nextJS backend and the route i am making the req to a protected route so in my Rest client file (req.rest) I need to tell auth0 im authenticated but i do not know how to do that.

req.rest

POST http://localhost:3000/api/video
Content-Type: application/json
Authorization: Bearer cookie

{
    "title": "Video",
    "description": "Video description"
}

api/video.js

import { withApiAuthRequired, getSession } from "@auth0/nextjs-auth0";
import Video from "../../database/models/Video";

export default withApiAuthRequired(async function handler(req, res) {
  if (req.method === "POST") {
    try {
      const { user } = getSession(req, res);

      const newVideo = new Video({
        title: req.body.title,
        description: req.body.description,
        ownerId: user.sub,
      });

      await newVideo.save();

      res.json(newVideo);
    } catch (error) {
      res.status(500).json({ error: error.message });
    }
  }
});

Solution

So I haven't really found a solution but I do have a workaround which is to just make new page on the frontend for requests and send the requests from there.



Answered By - Sajawal Hassan
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing