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

@elysiajs/jwt ^1.0.2 breaks type inference for handler functions #26

Open
Limitless-Kode opened this issue Mar 26, 2024 · 7 comments · May be fixed by #30
Open

@elysiajs/jwt ^1.0.2 breaks type inference for handler functions #26

Limitless-Kode opened this issue Mar 26, 2024 · 7 comments · May be fixed by #30

Comments

@Limitless-Kode
Copy link

I added @elysiajs/jwt ^1.0.2 to my project and initialised it with the .use hook. Everything seems to work fine however it breaks the type inference causing the handler method parameters to implicitly return a type of any.

    app.use(jwt({
        secret: env.JWT_SECRET,
        algorithms: ["HS256"],
        maxAge: "1d",
        clockTolerance: 0
    }))
    .get("/", async ({query, jwt, set, cookie: { auth }}) => {
            const verified = await jwt.verify(auth.value)
            if (!verified) {
                set.status = 401
                return 'Unauthorized'
            }
            const users = await AuthenticationController.all(query);
            return ApiResponse.success(users);
        },
        {
            detail: { tags: ["Authentication"] }
        }
    )

jwt, query, set, and auth now implicitly have the type of any

@luccaparadeda
Copy link

Up

@acrois acrois linked a pull request Apr 20, 2024 that will close this issue
@RickGeersing
Copy link

Any updates on this? Experiencing the same

@Limitless-Kode
Copy link
Author

Any updates on this? Experiencing the same

As a fix, I decided to convert the return value to an Elysia & { jwt: typeof jwt }

jwt({
  name: "jwt",
  secret: env.JWT_SECRET,
  algorithms: ["HS256"],
  ignoreExpiration: false,
  audience: "https://api.domain.com",
  issuer: "https://api.domain.com",
  maxAge: "1d",
  clockTolerance: 0,
}) as Elysia & { jwt: typeof jwt };

@RickGeersing
Copy link

Thanks, that is a workable fix for now

@RickGeersing
Copy link

Updating to the latest version (1.1.0) fixed it for me

@jvidalv
Copy link

jvidalv commented Dec 26, 2024

Only works on 1.1.0, any bigger version jwt is undefined.

"@elysiajs/eden": "1.1.3"
"elysia": "1.1.20"

No BUN.

@vigneshka
Copy link

adding @bun/types to dev dependency fixes things for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants