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

Jwt verify problems #15

Open
ImJustLucas opened this issue Oct 22, 2023 · 4 comments · Fixed by silverlyra/elysia-jwt#1
Open

Jwt verify problems #15

ImJustLucas opened this issue Oct 22, 2023 · 4 comments · Fixed by silverlyra/elysia-jwt#1

Comments

@ImJustLucas
Copy link

ImJustLucas commented Oct 22, 2023

Hello guys, i got a problem with the .verify method of the @elysia/jwt package.
I'm trying to verify my jwt token but it doesn't work and return false.
jwt.io tell me there is nothing wrong with my token

here is my code:

  const jwt = await jwtAccess.verify(cookie!.access_token);
  console.log("Test verify JWT", jwt, cookie!.access_token);
  if (!jwt) {
    set.status = 401;
    return {
      success: false,
      message: "Unauthorized",
      errors: "Invalid access token",
    };
  }

this code is in a middleware, and the cookie is set in the request.
the code of the jwtAccess.verify method is:

export const jwtAccessSetup = new Elysia({
  name: "jwtAccess",
}).use(
  jwt({
    name: "jwtAccess",
    schema: t.Object({
      userId: t.String(),
    }),
    secret: process.env.JWT_ACCESS_SECRET || "DO NOT USE THIS SECRET KEY",
    exp: 30 * 24 * 60 * 60,
  })
);

Even this, return false

const test = await jwtAccess.sign({ userId: "652e83d3b47c67a8d823daa6" });
console.log("@Cookie verify", await jwtAccess.verify(test));

every time i want to check the jwt, it returns me false but when i check it with the jwt.io debugger, it works.
is there a problem with the verify method or am i doing something wrong?

full repo: https://github.com/ImJustLucas/bun-elysia-boilerplate/tree/master

@MariuzM
Copy link

MariuzM commented Nov 7, 2023

Might be related to what i want #17

@ImJustLucas
Copy link
Author

We both got issue on .verify, my token here is not expired i'm sure about that

@silverlyra
Copy link

Verification can fail if there’s a schema defined. I’ve published my fork of this library which fixes that issue.

@ImJustLucas
Copy link
Author

Hello, i've forgot to write it here, but i've fixed this issue on my repo where i used it, with still the schema defined

here is what i changed, my problem was due to the exp property which doesn't take the actual date by default

image

after, thanks to new version of elysia, i could remove the @elisya/cookie package, and use the native usage if cookie

image

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.

3 participants