# Backend: "UnauthorizedError: No authorization token was found"

**URL:** <https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593>\
**Category:** Get Help\
**Tags:** jwt, api, auth0\
**Created:** [October 18, 2022, 2:17am UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593 "2022-10-18T02:17:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![athome176](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/athome176/32/40591_2.png) [@athome176](https://community.auth0.com/u/athome176)\
**Post date:** [October 18, 2022, 2:17am UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593/1 "2022-10-18T02:17:46Z")

</div>

I am trying to implement Auth0 on the backend of my ToDo list app but getting an “UnauthorizedError: No authorization token was found” error when trying to add a task.

Server.js:

```auto
const cors = require("cors");
const dotenv = require("dotenv");
const express = require("express");
const path = __dirname + '/app/views/';
const { tasksRouter } = require("./app/routes/task.routes");
const {checkJwt} = require("./app/middleware/check-jwt.middleware");

dotenv.config();

if (!(process.env.PORT && process.env.CLIENT_ORIGIN_URL)) {
    throw new Error(
        "Missing required environment variables. Check docs for more info."
    );
}

const PORT = parseInt(process.env.PORT, 10);
const CLIENT_ORIGIN_URL = process.env.CLIENT_ORIGIN_URL;

const app = express();

app.use(express.json());
app.use(express.static(path));

app.use((req, res, next) => {
    res.contentType("application/json; charset=utf-8");
    next();
});

app.use(
    cors({
        origin: "*"
    })
);

app.use(express.urlencoded({ extended: true })); /* bodyParser.urlencoded() is deprecated */

// simple route
app.get('/', function (req,res) {
    res.sendFile(path + "index.html");
});

app.get('/profile', checkJwt, function(req, res) {
});

//require("./app/routes/task.routes.js")(app);
app.use('/api/tasks', tasksRouter);

// set port, listen for requests
//const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}.`);
});

```

Task router:

```auto
const express = require("express");
const { checkJwt } = require("../middleware/check-jwt.middleware");
const tasks = require("../controllers/task.controller.js");

const tasksRouter = express.Router();

// Create a new Task
tasksRouter.post("/", checkJwt, tasks.create);

// Retrieve all Tasks
tasksRouter.get("/", checkJwt, tasks.findAll);

// Retrieve all published Tasks
tasksRouter.get("/completed", checkJwt, tasks.findAllCompleted);

// Retrieve a single Task with id
tasksRouter.get("/:id", checkJwt, tasks.findOne);

// Update a Task with id
tasksRouter.put("/:id", checkJwt, tasks.update);

// Delete a Task with id
tasksRouter.delete("/:id", checkJwt, tasks.delete);

// Delete all Tasks
tasksRouter.delete("/", checkJwt, tasks.deleteAll);

module.exports = { tasksRouter };

```

CheckJwt Middleware:

```auto
const { expressjwt: expressJwt } = require('express-jwt');
const jwksRsa = require("jwks-rsa");
const dotenv = require("dotenv");

dotenv.config();

const checkJwt = expressJwt({
  secret: jwksRsa.expressJwtSecret({
    cache: true,
    rateLimit: true,
    jwksRequestsPerMinute: 5,
    jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`,
  }),

  // Validate the audience and the issuer.
  audience: process.env.AUTH0_AUDIENCE,
  issuer: `https://${process.env.AUTH0_DOMAIN}/`,
  algorithms: ["RS256"],
});

module.exports = {
  checkJwt,
};

```

The page loads and operates as normal until I try to add a task at “/add”, when I get the unauthorized error. Any ideas?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 27, 2022, 10:11pm UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593/2 "2022-10-27T22:11:05Z")

</div>

Hi @athome176

Welcome to the Auth0 Community!

I am not seeing a route for `/add`. Are we missing something here?

Could you please show us an example of the request you are making?

---

<div class="post-metadata">

**Author:** ![athome176](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/athome176/32/40591_2.png) [@athome176](https://community.auth0.com/u/athome176)\
**Post date:** [November 6, 2022, 12:10am UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593/3 "2022-11-06T00:10:14Z")

</div>

Thanks for the reply. I was able to figure it out. My jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`,was done incorrectly. My env variable already included “https” so it was screwing up the URI as a whole.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 7, 2022, 11:40am UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593/4 "2022-11-07T11:40:29Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 21, 2022, 11:40am UTC](https://community.auth0.com/t/backend-unauthorizederror-no-authorization-token-was-found/92593/5 "2022-11-21T11:40:37Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
