Skip to content

CTX improvements for auth #232

Description

@jyecusch

Looks like you have to do a little parsing to get hold of the contents of the authentication token.

const authHeader = Array.isArray(ctx.req.headers["authorization"])
? ctx.req.headers["authorization"][0]
: ctx.req.headers["authorization"];
const accessToken: string | undefined = authHeader?.split(" ")[1];

const decoded = decoder.decode(accessToken);
const audience = decoded!["......"]; // claim

Suggestion to improve this in the SDKs by exposing the auth header tokens a little more cleanly.

If you've got your middleware in the same file as your handler, it can be a little messy with the imports as well since we have a naming conflict with jwt.

import { api, jwt } from "@nitric/sdk";
import { jwt as decoder } from "jsonwebtoken";

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions