auth-events 0.0.3 β 0.0.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 +147 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,31 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
 
|
|
4
4
|
|
|
5
|
-
**auth-events** is a lightweight, open-source Node.js library designed to **track, monitor, and react to authentication events** across any authentication provider.
|
|
6
5
|
|
|
7
|
-
While providers like Auth0, Clerk, or Firebase handle authentication, they do **not provide an easy way to control and respond to post-auth events**. This library fills that gap by giving developers **visibility, control, and automation** over everything that happens after login.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
# auth-events β Authentication Event Engine for Node.js
|
|
8
|
+
|
|
9
|
+
A lightweight, open-source Node.js library to **listen, track, and react to authentication events** in a clean, event-driven way.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Authentication providers like Auth0, Clerk, Firebase, or custom JWT systems handle authentication well β but they donβt give you enough control over what happens *after authentication.*
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- **Session Intelligence:** track active sessions, devices, locations, and token lifetimes
|
|
15
|
-
- **Rule Engine:** define custom logic for auth events (revoke sessions, force re-auth, trigger webhooks)
|
|
16
|
-
- **Provider-Agnostic:** works with Auth0, Clerk, Firebase, or any custom JWT auth
|
|
17
|
-
- **Developer-First:** minimal setup, zero magic, easy integration
|
|
13
|
+
Thatβs where **auth-events** fits in.
|
|
18
14
|
|
|
19
15
|
---
|
|
20
16
|
|
|
21
|
-
##
|
|
17
|
+
## π What Problem Does It Solve?
|
|
18
|
+
|
|
19
|
+
Most applications need to react when authentication events occur.
|
|
20
|
+
|
|
21
|
+
| Event | Purpose |
|
|
22
|
+
|------|--------|
|
|
23
|
+
| User logs in | Track activity |
|
|
24
|
+
| Password changes | Revoke sessions |
|
|
25
|
+
| Role changes | Sync permissions |
|
|
26
|
+
| Suspicious login | Trigger security flows |
|
|
27
|
+
|
|
28
|
+
Instead of scattering this logic across your backend, **auth-events centralizes it using events.**
|
|
29
|
+
|
|
30
|
+
---
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
## β¨ Features
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
34
|
+
- Event-Driven Authentication Logic
|
|
35
|
+
- Provider-Agnostic (Auth0, Clerk, Firebase, JWT, etc.)
|
|
36
|
+
- Strong TypeScript Support
|
|
37
|
+
- Full Post-Authentication Control
|
|
38
|
+
- Minimal & Lightweight
|
|
39
|
+
- No heavy dependencies
|
|
30
40
|
|
|
31
41
|
---
|
|
32
42
|
|
|
@@ -34,3 +44,124 @@ With **auth-events**, developers can:
|
|
|
34
44
|
|
|
35
45
|
```bash
|
|
36
46
|
npm install auth-events
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
or
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
yarn add auth-events
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## π§ Core Concept
|
|
58
|
+
|
|
59
|
+
You **emit events when authentication happens**, and **subscribe to them anywhere in your app.**
|
|
60
|
+
|
|
61
|
+
Supported event types:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export type AuthEventType =
|
|
65
|
+
| "login"
|
|
66
|
+
| "logout"
|
|
67
|
+
| "password_changed"
|
|
68
|
+
| "role_changed";
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## π¦ Basic Usage
|
|
74
|
+
|
|
75
|
+
### 1οΈβ£ Import the Library
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { auth } from "auth-events";
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### 2οΈβ£ Listen to Authentication Events
|
|
84
|
+
|
|
85
|
+
#### Login Event
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
auth.on("login", (event) => {
|
|
89
|
+
console.log(`User ${event.userId} logged in at ${event.timestamp}`);
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Password Change Event
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
auth.on("password_changed", (event) => {
|
|
97
|
+
console.log(`Password changed for user ${event.userId}`);
|
|
98
|
+
|
|
99
|
+
// Example:
|
|
100
|
+
// revokeAllSessions(event.userId);
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 3οΈβ£ Emit Events from Your Auth Logic
|
|
107
|
+
|
|
108
|
+
#### Example: Login Controller
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
auth.emit("login", {
|
|
112
|
+
userId: user.id,
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
ipAddress: req.ip,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Example: Password Update
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
auth.emit("password_changed", {
|
|
122
|
+
userId: user.id,
|
|
123
|
+
timestamp: Date.now(),
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## π οΈ Where Can You Use This?
|
|
130
|
+
|
|
131
|
+
- Security monitoring
|
|
132
|
+
- Session management
|
|
133
|
+
- Audit logs
|
|
134
|
+
- Analytics & tracking
|
|
135
|
+
- Notifications
|
|
136
|
+
- Role & permission syncing
|
|
137
|
+
- Compliance logging
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## π§© Works With
|
|
142
|
+
|
|
143
|
+
- Auth0
|
|
144
|
+
- Clerk
|
|
145
|
+
- Firebase Auth
|
|
146
|
+
- Custom JWT / Session Auth
|
|
147
|
+
- Any Node.js backend
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## π± Philosophy
|
|
152
|
+
|
|
153
|
+
**Authentication tells you who the user is.**
|
|
154
|
+
**auth-events tells you what to do next.**
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## π€ Contributing
|
|
159
|
+
|
|
160
|
+
Contributions and feedback are welcome.
|
|
161
|
+
Open an issue or submit a pull request π
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## π License
|
|
166
|
+
|
|
167
|
+
MIT License
|