auth-events 0.0.2
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 +36 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +36 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# auth-events
|
|
2
|
+
|
|
3
|
+
 
|
|
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
|
+
|
|
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
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🚀 Features
|
|
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
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 💡 Why Use auth-events?
|
|
22
|
+
|
|
23
|
+
Traditional auth providers solve "who the user is", but **what happens after login** is often messy and error-prone.
|
|
24
|
+
|
|
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
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## âš¡ Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install auth-events
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type AuthEventType = "login" | "logout" | "password_changed" | "role_changed";
|
|
2
|
+
interface AuthEvent {
|
|
3
|
+
type: AuthEventType;
|
|
4
|
+
userId: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
ip?: string;
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
timestamp: Date;
|
|
9
|
+
}
|
|
10
|
+
type AuthEventHandler = (event: AuthEvent, context: unknown) => void | Promise<void>;
|
|
11
|
+
|
|
12
|
+
declare class AuthEvents {
|
|
13
|
+
private bus;
|
|
14
|
+
on(type: AuthEventType, handler: AuthEventHandler): void;
|
|
15
|
+
emit(type: AuthEventType, payload: Omit<AuthEvent, "type" | "timestamp">): Promise<void>;
|
|
16
|
+
private createContext;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { AuthEvent, AuthEventHandler, AuthEventType, AuthEvents };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/core/EventBus.ts
|
|
2
|
+
var EventBus = class {
|
|
3
|
+
handlers = /* @__PURE__ */ new Map();
|
|
4
|
+
on(type, handler) {
|
|
5
|
+
const existing = this.handlers.get(type) ?? [];
|
|
6
|
+
this.handlers.set(type, [...existing, handler]);
|
|
7
|
+
}
|
|
8
|
+
async emit(event, context) {
|
|
9
|
+
const handlers = this.handlers.get(event.type) ?? [];
|
|
10
|
+
for (const handler of handlers) {
|
|
11
|
+
await handler(event, context);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/core/AuthEvents.ts
|
|
17
|
+
var AuthEvents = class {
|
|
18
|
+
bus = new EventBus();
|
|
19
|
+
on(type, handler) {
|
|
20
|
+
this.bus.on(type, handler);
|
|
21
|
+
}
|
|
22
|
+
async emit(type, payload) {
|
|
23
|
+
const event = {
|
|
24
|
+
type,
|
|
25
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
26
|
+
...payload
|
|
27
|
+
};
|
|
28
|
+
await this.bus.emit(event, this.createContext());
|
|
29
|
+
}
|
|
30
|
+
createContext() {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
AuthEvents
|
|
36
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "auth-events",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A lightweight Node.js library to track and react to authentication events across any auth provider.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/index.js",
|
|
16
|
+
"dist/index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Meraj Ansari",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"auth",
|
|
22
|
+
"authentication",
|
|
23
|
+
"sessions",
|
|
24
|
+
"events",
|
|
25
|
+
"nodejs",
|
|
26
|
+
"npm"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
30
|
+
"dev": "tsup src/index.ts --watch",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^6.6.0",
|
|
35
|
+
"typescript": "^5.1.6",
|
|
36
|
+
"@types/node": "^20.5.1",
|
|
37
|
+
"ts-node": "^10.9.1"
|
|
38
|
+
}
|
|
39
|
+
}
|