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

Cyrillic characters #938

Open
omqmo opened this issue Sep 2, 2023 · 2 comments
Open

Cyrillic characters #938

omqmo opened this issue Sep 2, 2023 · 2 comments

Comments

@omqmo
Copy link

omqmo commented Sep 2, 2023

How to fix this example?

import jwt from "jsonwebtoken";

// let o = { name: `Hello World!`}
let o = { name: `Привет Мир!`}
let token = jwt.sign( o, `secret`, {
  expiresIn: `1h`,
} );

let [, payload] = token.split( `.` );
let text = atob( payload ); // Error

In terminal npm start stackblitz

@miswanting
Copy link

Same here.

Some Chinese characters face the same problem.

import jwt from 'jsonwebtoken';

// let o = { name: `大` }; // OK case
let o = { name: `使` }; // Error case

let token = jwt.sign(o, `secret`, {
  expiresIn: `1h`,
});

let [, payload] = token.split(`.`);
console.log(payload);
let text = atob(payload); // throw Error
console.log(text);

stackblitz

@akalter
Copy link

akalter commented May 9, 2024

The issue is not related to this library.
If you will do btoa("使") you will have the same problem, the problem is the btoa/atob functions.

If you use jwt.verify or jwt.decode to extract the data from the jwt you will see that it is working as expected.

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

No branches or pull requests

3 participants