@tspscale/npm-login 1.0.0 → 1.0.1
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 +47 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @tspscale/npm-login
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for TSP Scale Authentication.
|
|
4
|
+
|
|
5
|
+
🚀 Quick Start (Zero-Config)
|
|
6
|
+
-----------------------------
|
|
7
|
+
Verify TSP Scale JWT access tokens securely from your backend server.
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
```bash
|
|
11
|
+
npm install @tspscale/npm-login
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
🛠️ Usage
|
|
15
|
+
---------
|
|
16
|
+
You can easily protect your Express or Next.js routes using the built-in middleware or by manually verifying tokens.
|
|
17
|
+
|
|
18
|
+
### Express Middleware
|
|
19
|
+
```javascript
|
|
20
|
+
const express = require('express');
|
|
21
|
+
const { tspAuth } = require('@tspscale/npm-login');
|
|
22
|
+
|
|
23
|
+
const app = express();
|
|
24
|
+
|
|
25
|
+
// Protect a route - requires a Bearer token in the Authorization header
|
|
26
|
+
app.get('/api/protected', tspAuth.middleware(), (req, res) => {
|
|
27
|
+
// The middleware automatically attaches the user profile to the request
|
|
28
|
+
res.json({ message: "Success!", user: req.user });
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Manual Token Verification
|
|
33
|
+
If you are using Next.js or a custom server, you can manually verify a token:
|
|
34
|
+
```javascript
|
|
35
|
+
const { tspAuth } = require('@tspscale/npm-login');
|
|
36
|
+
|
|
37
|
+
async function checkToken(accessToken) {
|
|
38
|
+
const result = await tspAuth.verifyToken(accessToken);
|
|
39
|
+
|
|
40
|
+
if (result.error) {
|
|
41
|
+
console.error("Verification failed:", result.error);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log("User Profile:", result.user);
|
|
46
|
+
}
|
|
47
|
+
```
|