auth-events 0.0.4 β†’ 0.0.6

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.
Files changed (2) hide show
  1. package/README.md +147 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,31 +2,41 @@
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/auth-events) ![license](https://img.shields.io/github/license/<your-username>/auth-events)
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
- ## πŸš€ Features
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
- - **Unified Event Tracking:** login, logout, password changes, role updates β€” all in one consistent API
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
- ## πŸ’‘ Why Use auth-events?
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
- Traditional auth providers solve "who the user is", but **what happens after login** is often messy and error-prone.
32
+ ## ✨ Features
24
33
 
25
- With **auth-events**, developers can:
26
- - Track all user sessions and devices
27
- - Automatically enforce security rules (e.g., revoke old sessions after password change)
28
- - React to suspicious logins or role changes
29
- - Gain peace of mind and focus on business logic instead of boilerplate auth management
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth-events",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A lightweight Node.js library to track and react to authentication events across any auth provider.",
5
5
  "type": "module",
6
6
  "license": "MIT",