Commit 047dab2b by Percy Quispe Huarcaya

feat: Adding token creator and a parser

parent 16f04627
...@@ -51,6 +51,8 @@ parseJWT = (token, ...id) => { ...@@ -51,6 +51,8 @@ parseJWT = (token, ...id) => {
} }
} }
*/ */
console.log("parseJWT -------");
console.log(decoded)
return decoded; // This will return the token's claims (payload) return decoded; // This will return the token's claims (payload)
} catch (err) { } catch (err) {
console.error('Invalid token:', err.message); console.error('Invalid token:', err.message);
......
import { JwtPayload } from "jsonwebtoken"; import { TokenModel } from "./tokenmodel";
/** /**
JwtPayload TokenModel
[key: string]: any; id: string;
iss?: string | undefined; issuedAt: number;
sub?: string | undefined; subject: object;
aud?: string | string[] | undefined; issuer: string;
exp?: number | undefined; iat: number;
nbf?: number | undefined; exp: number;
iat?: number | undefined;
jti?: string | undefined;
*/ */
declare module 'security-ndjs-lib' { declare module 'security-ndjs-lib' {
export function createJWT(id: string, subject: object, time?: number): string; export function createJWT(id: string, subject: object, time?: number): string;
export function parseJWT(token?: string, id?: string): JwtPayload; // Adjust the signature if needed export function parseJWT(token?: string, id?: string): TokenModel; // Adjust the signature if needed
} }
\ No newline at end of file
export interface TokenModel {
id: string;
issuedAt: number;
subject: object;
issuer: string;
iat: number;
exp: number;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment