secure-web-token 1.2.4 → 1.2.5
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/README.md +12 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,6 @@ Validates and decrypts the token, ensuring the request comes from the **correct
|
|
|
63
63
|
## 4. Boiler Code (Core Usage)
|
|
64
64
|
|
|
65
65
|
### `sign()` function
|
|
66
|
-
|
|
67
66
|
```ts
|
|
68
67
|
import { sign } from "secure-web-token";
|
|
69
68
|
|
|
@@ -83,7 +82,6 @@ const { token, sessionId } = sign(
|
|
|
83
82
|
---
|
|
84
83
|
|
|
85
84
|
### `verify()` function
|
|
86
|
-
|
|
87
85
|
```ts
|
|
88
86
|
import { verify, getStore } from "secure-web-token";
|
|
89
87
|
|
|
@@ -102,16 +100,16 @@ const payload = verify(token, SECRET, {
|
|
|
102
100
|
## 5. Demo App
|
|
103
101
|
|
|
104
102
|
### Backend (Express.js + Node.js)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const { sign, verify, getStore } = require("secure-web-token");
|
|
103
|
+
```ts
|
|
104
|
+
import express from "express";
|
|
105
|
+
import cookieParser from "cookie-parser";
|
|
106
|
+
import cors from "cors";
|
|
107
|
+
import { sign, verify, getStore } from "secure-web-token";
|
|
111
108
|
|
|
112
109
|
const app = express();
|
|
113
110
|
app.use(cors({ origin: true, credentials: true }));
|
|
114
111
|
app.use(cookieParser());
|
|
112
|
+
app.use(express.json());
|
|
115
113
|
|
|
116
114
|
const SECRET = "super-secret-key";
|
|
117
115
|
const store = getStore("memory");
|
|
@@ -149,12 +147,13 @@ app.get("/profile", (req, res) => {
|
|
|
149
147
|
app.listen(4000);
|
|
150
148
|
```
|
|
151
149
|
|
|
152
|
-
---
|
|
153
|
-
|
|
154
150
|
### Frontend (React.js)
|
|
151
|
+
```tsx
|
|
152
|
+
import { useState } from "react";
|
|
155
153
|
|
|
156
|
-
```js
|
|
157
154
|
function App() {
|
|
155
|
+
const [user, setUser] = useState(null);
|
|
156
|
+
|
|
158
157
|
const login = async () => {
|
|
159
158
|
const res = await fetch("http://localhost:4000/login", {
|
|
160
159
|
method: "POST",
|
|
@@ -187,7 +186,6 @@ export default App;
|
|
|
187
186
|
---
|
|
188
187
|
|
|
189
188
|
## 6. Payload Structure
|
|
190
|
-
|
|
191
189
|
```json
|
|
192
190
|
{
|
|
193
191
|
"data": {
|
|
@@ -202,16 +200,14 @@ export default App;
|
|
|
202
200
|
|
|
203
201
|
---
|
|
204
202
|
|
|
205
|
-
## Installation
|
|
206
|
-
|
|
203
|
+
## 7. Installation
|
|
207
204
|
```bash
|
|
208
205
|
npm install secure-web-token
|
|
209
206
|
```
|
|
210
207
|
|
|
211
208
|
---
|
|
212
209
|
|
|
213
|
-
## Importing
|
|
214
|
-
|
|
210
|
+
## 8. Importing
|
|
215
211
|
```ts
|
|
216
212
|
// ESM
|
|
217
213
|
import { sign, verify, getStore } from "secure-web-token";
|