Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTX improvements for auth #232

Open
jyecusch opened this issue Sep 24, 2024 · 0 comments
Open

CTX improvements for auth #232

jyecusch opened this issue Sep 24, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jyecusch
Copy link
Member

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";

@jyecusch jyecusch added the enhancement New feature or request label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant