Skip to content

Commit 966efc2

Browse files
author
eesteban
committed
feat: add jwt client
1 parent ecb19a0 commit 966efc2

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ export interface IOptions {
77
export function decode(token: string, key: string, noVerify?: boolean, algorithm?: TAlgorithm): any;
88

99
export function encode(payload: any, key: string, algorithm?: TAlgorithm, options?: IOptions): string;
10+
11+
export function client<T>(key: string, algorithm?: TAlgorithm, options?: IOptions): {
12+
encode: (payload: T) => string,
13+
decode: (token: string, noVerify: boolean) => T
14+
};

lib/jwt.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ jwt.encode = function jwt_encode(payload, key, algorithm, options) {
145145
return segments.join('.');
146146
};
147147

148+
/**
149+
* Generate jwt client
150+
*
151+
* @param {String} key
152+
* @param {String} algorithm
153+
* @param {Object} options
154+
* @return {Object} client
155+
* @api public
156+
*/
157+
jwt.client = function jwt_client(key, algorithm, options) {
158+
return {
159+
encode: function (payload) {
160+
return jwt_encode(payload, key, algorithm, options);
161+
},
162+
decode: function (token, noVerify) {
163+
return jwt_decode(token, key, noVerify, algorithm);
164+
},
165+
}
166+
};
167+
148168
/**
149169
* private util functions
150170
*/

0 commit comments

Comments
 (0)