@@ -63,9 +63,9 @@ yarn add @bepalo/jwt
6363``` ts
6464Import directly using the URL :
6565
66- import { Time } from " npm:@bepalo/jwt" ;
66+ import { JWT } from " npm:@bepalo/jwt" ;
6767// or
68- import { Time } from " jsr:@bepalo/jwt" ;
68+ import { JWT } from " jsr:@bepalo/jwt" ;
6969```
7070
7171## 🚀 Quick Start
@@ -75,20 +75,20 @@ import { Time } from "jsr:@bepalo/jwt";
7575``` ts
7676import { JWT } from " @bepalo/jwt" ;
7777
78- // 🏁 1. Generate a key
78+ // 1. Generate a key
7979const secret = JWT .genHmac (" HS256" );
8080
81- // 🏁 2. Store the generated key somewhere safe like in a .env file
81+ // 2. Store the generated key somewhere safe like in a .env file
8282console .log (secret );
8383
84- // 🏁 3. Load that key from where it was stored
84+ // 3. Load that key from where it was stored
8585const signKey = process .env .SECRET ;
8686const verifyKey = process .env .SECRET ;
8787
88- // 🏁 4. Create a JWT instance for signing
88+ // 4. Create a JWT instance for signing
8989const jwtSign = JWT .createSymmetric (signKey , " HS256" );
9090
91- // 🏁 5. Sign a payload
91+ // 5. Sign a payload
9292const token = jwtSign .signSync ({
9393 userId: 123 ,
9494 role: " admin" ,
@@ -99,16 +99,16 @@ const token = jwtSign.signSync({
9999 // ...
100100});
101101
102- // 🏁 6. Create another JWT instance for verifying. *optional*
102+ // 6. Create another JWT instance for verifying. *optional*
103103const jwtVerify = JWT .createSymmetric (verifyKey , " HS256" );
104104
105- // 🏁 7. Verify and decode the token
105+ // 7. Verify and decode the token
106106const { valid, payload, error } = jwtVerify .verifySync (token , {
107107 jti: " tid-1234" ,
108108 nbfLeeway: JWT .for (5 ).Seconds
109109});
110110
111- // 🏁 8. Deal with errors or use the payload
111+ // 8. Deal with errors or use the payload
112112console .log (valid ); // true
113113console .log (payload ); // { userId: 123, role: "admin", ... }
114114console .log (error ); // undefined
@@ -119,22 +119,22 @@ console.log(error); // undefined
119119``` ts
120120import { JWT } from " @bepalo/jwt" ;
121121
122- // 🏁 1. Generate a key
122+ // 1. Generate a key
123123const key = JWT .genKey (" ES256" );
124124
125- // 🏁 2. Store the generated key somewhere safe like in a .env file
125+ // 2. Store the generated key somewhere safe like in a .env file
126126const { alg, publicKey, privateKey } = key ;
127127console .log (JSON .stringify ({ alg , publicKey }));
128128console .log (JSON .stringify ({ alg , privateKey }));
129129
130- // 🏁 3. Load that key from where it was stored
130+ // 3. Load that key from where it was stored
131131const signKey = JSON .parse (process .env .PRIVATE_KEY ?? " null" );
132132const verifyKey = JSON .parse (process .env .PUBLIC_KEY ?? " null" );
133133
134- // 🏁 4. Create a JWT instance for signing
134+ // 4. Create a JWT instance for signing
135135const jwtSign = JWT .create (signKey );
136136
137- // 🏁 5. Sign a payload
137+ // 5. Sign a payload
138138const token = jwtSign .signSync ({
139139 userId: 123 ,
140140 role: " admin" ,
@@ -145,16 +145,16 @@ const token = jwtSign.signSync({
145145 // ...
146146});
147147
148- // 🏁 6. Create a JWT instance for verifying
148+ // 6. Create a JWT instance for verifying
149149const jwtVerify = JWT .create (verifyKey );
150150
151- // 🏁 7. Verify and decode the token
151+ // 7. Verify and decode the token
152152const { valid, payload, error } = jwtVerify .verifySync (token , {
153153 jti: " tid-1234" ,
154154 nbfLeeway: JWT .for (5 ).Seconds
155155});
156156
157- // 🏁 8. Deal with errors or use the payload
157+ // 8. Deal with errors or use the payload
158158console .log (valid ); // true
159159console .log (payload ); // { userId: 123, role: "admin", ... }
160160console .log (error ); // undefined
0 commit comments