#Jwt verification problem with elysia

1 messages · Page 1 of 1 (latest)

upper charm
#

Hello guys, i got a problem with the .verify method of the @elysia/jwt package.
I'm trying to verify a 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,
  })
);

every time i want to check the jwt, it returns me false but when i check it with the jwt.io debugger, it works.

Even this, return false 💀

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

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>
silent plank
#

@upper charm go to Elysia discord server

#

@eager ravine

upper charm
#

I already sent a message there!

silent plank
#

what is that cookie thing @upper charm

#

cookie.access_token

#

did you check the cookie?

upper charm
#

its the way i get the cookie, access_token is the name

#

yes, just above

silent plank
#

I thought the schema is sth like
schema: {
body: { ... },
cookie: { ... }
} @upper charm

#

idk much about elysia cuz i made my own thing

upper charm
#

the schema for the setup ?
i use the elysia/cookie plugin

but here is not a cookie prob, its the verify method, it seems that whatever i'll write, the method will always return false

#

the last exemple of code show it

silent plank
#

hope @eager ravine can help

upper charm
#

hope too 😄

silent plank
#

also I made my fast cookie parser
but I didn't touch JWT yet cuz I will try to use Vix tokens

#

(8x faster than JWT)

upper charm
#

i've never heard about Vix token!

#

i'll take a look when i got free time

silent plank
#

I want to use that cuz my framework is focused on performance

#

(but its DX is still better than many)

upper charm
#

will try soon so, looks interesting

#

I just discovered bun this week

silent plank
#

elysia is still popular than mine when you search for Bun HTTP framework

upper charm
#

yep, that why my teacher tell me to use elysia! and thats why i need to solve this bug for today lol

but i'll try yours soon to get my own opinion

silent plank
#

DM me if you have any issue or feature request when using mine 😅

upper charm
#

of course!

dusk forge
#

Yeah, I got stuck at college but I should be shipping it next week

#

But it's way faster

#

But everything related with crypto has to be tested over and over checking all the edge cases and that's time consuming as hell