Skip to content

Commit c264b06

Browse files
committed
Use jwt-decode instead of jsonwebtoken so this library can work in the browser
1 parent fb7d9e3 commit c264b06

File tree

3 files changed

+29
-198
lines changed

3 files changed

+29
-198
lines changed

package-lock.json

Lines changed: 17 additions & 190 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"dependencies": {
7373
"ip-address": "^8.1.0",
7474
"json5": "^2.2.0",
75-
"jsonwebtoken": "^8.5.1",
75+
"jwt-decode": "^3.1.2",
7676
"universal-url": "^2.0.0",
7777
"uuid": "^8.3.2"
7878
},
@@ -90,4 +90,4 @@
9090
"pre-commit": "npm run prettier-format && npm run lint"
9191
}
9292
}
93-
}
93+
}

src/formats/jwt.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import jwt from "jsonwebtoken";
1+
import jwtDecode from "jwt-decode";
22

33
export type JSONJWTStringFormat = {
44
name: "jwt";
55
};
66

77
export function inferJWT(value: string): JSONJWTStringFormat | undefined {
8-
const token = jwt.decode(value);
8+
try {
9+
const token = jwtDecode(value);
910

10-
if (token) {
11-
return {
12-
name: "jwt",
13-
};
11+
if (token) {
12+
return {
13+
name: "jwt",
14+
};
15+
}
16+
} catch {
17+
// ignore
1418
}
1519

1620
return undefined;

0 commit comments

Comments
 (0)