I'm trying to create a middleware in Deno using oak, I want to validate a jwt token and then if everything is OK add the payload to the request body.
Found this code:
import { validateJwt } from "https://deno.land/x/djwt/validate.ts" import { key } from "../utils/jwt.js"; export const validate = async ({request, cookies}, next) => { const token = await cookies.get("token"); const result = await validateJwt(token, key, { isThrowing: false }); if(result) { request.auth = true; request.username = result.payload.username; } await next(); }
but is not working any more and haven't been able to find anything about how to add properties to the request.
What I want to achieve at the end is to access the payload inside the controller.
Thanks in advance. Any guidance will be much appreciated
https://stackoverflow.com/questions/66994776/deno-middleware-to-add-payload-to-request April 08, 2021 at 06:09AM
没有评论:
发表评论