@valbuild/server 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/jwt.d.ts +7 -1
- package/package.json +1 -1
- package/src/jwt.ts +12 -2
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JwtPayload = {
|
|
2
|
+
sub: string;
|
|
3
|
+
exp: number;
|
|
4
|
+
org: string;
|
|
5
|
+
project: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function decodeJwt(token: string, secretKey?: string): JwtPayload | null;
|
|
2
8
|
export declare function getExpire(): number;
|
|
3
9
|
export declare function encodeJwt(payload: object, sessionKey: string): string;
|
package/package.json
CHANGED
package/src/jwt.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import crypto from "crypto";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export type JwtPayload = {
|
|
5
|
+
sub: string;
|
|
6
|
+
exp: number;
|
|
7
|
+
org: string;
|
|
8
|
+
project: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function decodeJwt(
|
|
12
|
+
token: string,
|
|
13
|
+
secretKey?: string
|
|
14
|
+
): JwtPayload | null {
|
|
5
15
|
const [headerBase64, payloadBase64, signatureBase64, ...rest] =
|
|
6
16
|
token.split(".");
|
|
7
17
|
if (!headerBase64 || !payloadBase64 || !signatureBase64 || rest.length > 0) {
|
|
@@ -47,7 +57,7 @@ export function decodeJwt(token: string, secretKey?: string): unknown | null {
|
|
|
47
57
|
try {
|
|
48
58
|
const parsedPayload = JSON.parse(
|
|
49
59
|
Buffer.from(payloadBase64, "base64").toString("utf8")
|
|
50
|
-
) as
|
|
60
|
+
) as JwtPayload;
|
|
51
61
|
return parsedPayload;
|
|
52
62
|
} catch (err) {
|
|
53
63
|
console.debug("Invalid JWT: could not parse payload", err);
|