@trust-proto/auth-react 0.1.0
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/LICENSE +21 -0
- package/README.md +137 -0
- package/build/index.js +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Liberion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Liberion Auth - Integration Guide
|
|
2
|
+
|
|
3
|
+
Liberion Auth is a modern authentication widget for web applications.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation as NPM Package
|
|
8
|
+
|
|
9
|
+
Install the npm package:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @trust-proto/auth-react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### React Example with NPM Package
|
|
16
|
+
|
|
17
|
+
**Props:**
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Required | Description |
|
|
20
|
+
| ------------ | ---------- | -------- | ------------------------------------------------------------------ |
|
|
21
|
+
| `backendUrl` | `string` | ✅ | WebSocket authentication server URL |
|
|
22
|
+
| `isOpen` | `boolean` | ✅ | Controls widget visibility (true/false) |
|
|
23
|
+
| `theme` | `string` | ❌ | Theme mode: `'light'` or `'dark'` (default: `'dark'`) |
|
|
24
|
+
| `successCb` | `function` | ❌ | Callback function called on success. Receives authentication token |
|
|
25
|
+
| `failedCb` | `function` | ❌ | Callback function called on error. |
|
|
26
|
+
| `closeCb` | `function` | ❌ | Callback function called when widget is closed |
|
|
27
|
+
|
|
28
|
+
Import the widget into your React application:
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
import { useState } from "react";
|
|
32
|
+
import { LiberionAuth } from "@trust-proto/auth-react";
|
|
33
|
+
|
|
34
|
+
function App() {
|
|
35
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<button onClick={() => setIsOpen(true)}>Login with Liberion ID</button>
|
|
40
|
+
|
|
41
|
+
<LiberionAuth
|
|
42
|
+
backendUrl="wss://your-backend-url.example.com"
|
|
43
|
+
isOpen={isOpen}
|
|
44
|
+
theme="light"
|
|
45
|
+
closeCb={() => setIsOpen(false)}
|
|
46
|
+
successCb={(result) => {
|
|
47
|
+
console.log("Authentication successful, result:", result);
|
|
48
|
+
localStorage.setItem("authToken", result.token);
|
|
49
|
+
}}
|
|
50
|
+
failedCb={(error) => {
|
|
51
|
+
console.error("Authentication failed:", error);
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default App;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### React Example with script tag
|
|
62
|
+
|
|
63
|
+
```jsx
|
|
64
|
+
import React, { useState, useEffect } from "react";
|
|
65
|
+
|
|
66
|
+
const App = () => {
|
|
67
|
+
const [isWidgetLoaded, setIsWidgetLoaded] = useState(false);
|
|
68
|
+
const [token, setToken] = useState(null);
|
|
69
|
+
|
|
70
|
+
// Load widget script
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const script = document.createElement("script");
|
|
73
|
+
script.src = "https://cdn.statically.io/gh/liberion-official/auth-sdk-frontend/main/build/index.js";
|
|
74
|
+
script.async = true;
|
|
75
|
+
script.onload = () => setIsWidgetLoaded(true);
|
|
76
|
+
document.body.appendChild(script);
|
|
77
|
+
|
|
78
|
+
return () => {
|
|
79
|
+
document.body.removeChild(script);
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
// Check for existing token
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const savedToken = localStorage.getItem("authToken");
|
|
86
|
+
if (savedToken) {
|
|
87
|
+
setToken(savedToken);
|
|
88
|
+
}
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const handleLogin = () => {
|
|
92
|
+
if (!isWidgetLoaded) return;
|
|
93
|
+
|
|
94
|
+
window.LiberionAuth.open({
|
|
95
|
+
backendUrl: "wss://your-backend-url.example.com",
|
|
96
|
+
successCb: (result) => {
|
|
97
|
+
console.log("Authentication successful, result:", result);
|
|
98
|
+
localStorage.setItem("authToken", result.token);
|
|
99
|
+
setToken(result.token);
|
|
100
|
+
},
|
|
101
|
+
failedCb: (error) => {
|
|
102
|
+
console.error("Authentication failed:", error);
|
|
103
|
+
},
|
|
104
|
+
closeCb: () => {
|
|
105
|
+
console.log("Widget closed");
|
|
106
|
+
},
|
|
107
|
+
theme: "light",
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const handleLogout = () => {
|
|
112
|
+
localStorage.removeItem("authToken");
|
|
113
|
+
setToken(null);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (!token) {
|
|
117
|
+
return (
|
|
118
|
+
<div>
|
|
119
|
+
<h1>Welcome!</h1>
|
|
120
|
+
<button onClick={handleLogin} disabled={!isWidgetLoaded}>
|
|
121
|
+
{isWidgetLoaded ? "Login" : "Loading..."}
|
|
122
|
+
</button>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div>
|
|
129
|
+
<h1>You are authenticated!</h1>
|
|
130
|
+
<p>Token: {token.substring(0, 20)}...</p>
|
|
131
|
+
<button onClick={handleLogout}>Logout</button>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export default App;
|
|
137
|
+
```
|