@eventuras/fides-auth-next 0.8.1 → 1.0.0-beta.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/README.md +149 -109
- package/dist/auth.d.ts +79 -54
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +64 -75
- package/dist/auth.js.map +1 -1
- package/dist/cookie-store.d.ts +3 -5
- package/dist/cookie-store.d.ts.map +1 -1
- package/dist/cookie-store.js +3 -8
- package/dist/cookie-store.js.map +1 -1
- package/dist/index.d.ts +4 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -18
- package/package.json +8 -42
- package/dist/cookies.d.ts +0 -132
- package/dist/cookies.d.ts.map +0 -1
- package/dist/cookies.js +0 -220
- package/dist/cookies.js.map +0 -1
- package/dist/heartbeat-handler.d.ts +0 -36
- package/dist/heartbeat-handler.d.ts.map +0 -1
- package/dist/heartbeat-handler.js +0 -40
- package/dist/heartbeat-handler.js.map +0 -1
- package/dist/oidc-callback.d.ts +0 -60
- package/dist/oidc-callback.d.ts.map +0 -1
- package/dist/oidc-callback.js +0 -45
- package/dist/oidc-callback.js.map +0 -1
- package/dist/oidc-login.d.ts +0 -37
- package/dist/oidc-login.d.ts.map +0 -1
- package/dist/oidc-login.js +0 -36
- package/dist/oidc-login.js.map +0 -1
- package/dist/oidc-logout.d.ts +0 -56
- package/dist/oidc-logout.d.ts.map +0 -1
- package/dist/oidc-logout.js +0 -47
- package/dist/oidc-logout.js.map +0 -1
- package/dist/request.d.ts +0 -11
- package/dist/request.d.ts.map +0 -1
- package/dist/request.js +0 -43
- package/dist/request.js.map +0 -1
- package/dist/store/index.d.ts +0 -103
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -3
package/dist/request.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
3
|
-
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
4
|
-
*/
|
|
5
|
-
export declare function globalGETRateLimit(): Promise<boolean>;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
8
|
-
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function globalPOSTRateLimit(): Promise<boolean>;
|
|
11
|
-
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB5D"}
|
package/dist/request.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { headers } from "next/headers";
|
|
2
|
-
import { TokenBucket } from "@eventuras/fides-auth/rate-limit";
|
|
3
|
-
import { createLogger } from "@eventuras/fides-auth/logger";
|
|
4
|
-
// src/request.ts
|
|
5
|
-
var logger = createLogger({ namespace: "fides-auth-next:request" });
|
|
6
|
-
var globalBucket = null;
|
|
7
|
-
function getBucket() {
|
|
8
|
-
if (!globalBucket) globalBucket = new TokenBucket(100, 1);
|
|
9
|
-
return globalBucket;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
13
|
-
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
14
|
-
*/
|
|
15
|
-
async function globalGETRateLimit() {
|
|
16
|
-
try {
|
|
17
|
-
const clientIP = (await headers()).get("X-Forwarded-For");
|
|
18
|
-
if (clientIP === null) return true;
|
|
19
|
-
return getBucket().consume(clientIP, 1);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
if (error instanceof Error && error.message.includes("worker")) logger.error({ error }, "Worker thread error in globalGETRateLimit");
|
|
22
|
-
else logger.error({ error }, "Unexpected error in globalGETRateLimit");
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
28
|
-
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
29
|
-
*/
|
|
30
|
-
async function globalPOSTRateLimit() {
|
|
31
|
-
try {
|
|
32
|
-
const clientIP = (await headers()).get("X-Forwarded-For");
|
|
33
|
-
if (clientIP === null) return true;
|
|
34
|
-
return getBucket().consume(clientIP, 3);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
if (error instanceof Error && error.message.includes("worker")) logger.error({ error }, "Worker thread error in globalPOSTRateLimit");
|
|
37
|
-
else logger.error({ error }, "Unexpected error in globalPOSTRateLimit");
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export { globalGETRateLimit, globalPOSTRateLimit };
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=request.js.map
|
package/dist/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","names":[],"sources":["../src/request.ts"],"sourcesContent":["import { headers } from 'next/headers';\nimport {TokenBucket} from '@eventuras/fides-auth/rate-limit';\nimport { createLogger } from '@eventuras/fides-auth/logger';\n\nconst logger = createLogger({ namespace: 'fides-auth-next:request' });\n\n// Initialize bucket lazily to avoid worker thread issues\nlet globalBucket: TokenBucket<string> | null = null;\n\nfunction getBucket(): TokenBucket<string> {\n if (!globalBucket) {\n globalBucket = new TokenBucket<string>(100, 1);\n }\n return globalBucket;\n}\n\n/**\n * @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.\n * Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.\n */\nexport async function globalGETRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 1);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalGETRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalGETRateLimit');\n }\n return true;\n }\n}\n\n/**\n * @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.\n * Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.\n */\nexport async function globalPOSTRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 3);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalPOSTRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalPOSTRateLimit');\n }\n return true;\n }\n}\n"],"mappings":";;;;AAIA,IAAM,SAAS,aAAa,EAAE,WAAW,0BAA0B,CAAC;AAGpE,IAAI,eAA2C;AAE/C,SAAS,YAAiC;CACxC,IAAI,CAAC,cACH,eAAe,IAAI,YAAoB,KAAK,CAAC;CAE/C,OAAO;AACT;;;;;AAMA,eAAsB,qBAAuC;CAC3D,IAAI;EAEF,MAAM,YAAW,MADS,QAAQ,EAAA,CACL,IAAI,iBAAiB;EAClD,IAAI,aAAa,MACf,OAAO;EAET,OAAO,UAAU,CAAC,CAAC,QAAQ,UAAU,CAAC;CACxC,SAAS,OAAO;EAEd,IAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,QAAQ,GAC3D,OAAO,MAAM,EAAE,MAAM,GAAG,2CAA2C;OAEnE,OAAO,MAAM,EAAE,MAAM,GAAG,wCAAwC;EAElE,OAAO;CACT;AACF;;;;;AAMA,eAAsB,sBAAwC;CAC5D,IAAI;EAEF,MAAM,YAAW,MADS,QAAQ,EAAA,CACL,IAAI,iBAAiB;EAClD,IAAI,aAAa,MACf,OAAO;EAET,OAAO,UAAU,CAAC,CAAC,QAAQ,UAAU,CAAC;CACxC,SAAS,OAAO;EAEd,IAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,QAAQ,GAC3D,OAAO,MAAM,EAAE,MAAM,GAAG,4CAA4C;OAEpE,OAAO,MAAM,EAAE,MAAM,GAAG,yCAAyC;EAEnE,OAAO;CACT;AACF"}
|
package/dist/store/index.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication Store for Next.js
|
|
3
|
-
*
|
|
4
|
-
* This package provides XState Store-based authentication state management:
|
|
5
|
-
*
|
|
6
|
-
* - Simpler data-focused state management
|
|
7
|
-
* - Easier to understand and maintain
|
|
8
|
-
* - Perfect for authentication data and status
|
|
9
|
-
* - Apps can build complex workflows on top if needed
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { createAuthStore, createAuthStoreHooks, initializeAuth, startSessionMonitor } from '@eventuras/fides-auth-next/store';
|
|
16
|
-
* import { getAuthStatus } from './auth/getAuthStatus';
|
|
17
|
-
*
|
|
18
|
-
* // Create the store
|
|
19
|
-
* export const authStore = createAuthStore({
|
|
20
|
-
* checkAuthStatus: getAuthStatus,
|
|
21
|
-
* config: {
|
|
22
|
-
* adminRole: 'Admin',
|
|
23
|
-
* loggerNamespace: 'myapp:auth',
|
|
24
|
-
* }
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* // Create hooks
|
|
28
|
-
* export const { useAuthStore, useAuthActions } = createAuthStoreHooks(authStore);
|
|
29
|
-
*
|
|
30
|
-
* // In your root component
|
|
31
|
-
* function App() {
|
|
32
|
-
* useEffect(() => {
|
|
33
|
-
* // Initialize auth on mount
|
|
34
|
-
* initializeAuth(authStore, getAuthStatus);
|
|
35
|
-
*
|
|
36
|
-
* // Start session monitoring
|
|
37
|
-
* return startSessionMonitor(authStore, getAuthStatus, {
|
|
38
|
-
* interval: 30_000,
|
|
39
|
-
* onSessionExpired: () => {
|
|
40
|
-
* toast.warn('Your session has expired');
|
|
41
|
-
* }
|
|
42
|
-
* });
|
|
43
|
-
* }, []);
|
|
44
|
-
*
|
|
45
|
-
* return <div>...</div>;
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* // In any component
|
|
49
|
-
* function MyComponent() {
|
|
50
|
-
* const auth = useAuthStore();
|
|
51
|
-
* const { logout } = useAuthActions();
|
|
52
|
-
*
|
|
53
|
-
* if (auth.isInitializing) return <Spinner />;
|
|
54
|
-
* if (!auth.isAuthenticated) return <LoginButton />;
|
|
55
|
-
*
|
|
56
|
-
* return (
|
|
57
|
-
* <div>
|
|
58
|
-
* Welcome, {auth.user?.name}!
|
|
59
|
-
* <button onClick={logout}>Logout</button>
|
|
60
|
-
* </div>
|
|
61
|
-
* );
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* ## Building Complex Workflows
|
|
66
|
-
*
|
|
67
|
-
* You can use the Store for data management and build app-specific
|
|
68
|
-
* state machines that consume the auth store for complex workflows:
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* import { createMachine } from 'xstate';
|
|
73
|
-
* import { authStore } from './auth-store';
|
|
74
|
-
*
|
|
75
|
-
* const checkoutMachine = createMachine({
|
|
76
|
-
* context: ({ input }) => ({
|
|
77
|
-
* authStore: input.authStore,
|
|
78
|
-
* cart: [],
|
|
79
|
-
* }),
|
|
80
|
-
* states: {
|
|
81
|
-
* idle: {
|
|
82
|
-
* on: {
|
|
83
|
-
* START_CHECKOUT: {
|
|
84
|
-
* target: 'checkingAuth',
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
* },
|
|
88
|
-
* checkingAuth: {
|
|
89
|
-
* entry: ({ context }) => {
|
|
90
|
-
* const auth = context.authStore.getSnapshot().context;
|
|
91
|
-
* if (!auth.isAuthenticated) {
|
|
92
|
-
* // Trigger login flow
|
|
93
|
-
* }
|
|
94
|
-
* },
|
|
95
|
-
* // ... rest of workflow
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
* });
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export { createAuthStore, initializeAuth, checkAuth, startSessionMonitor, configureAuthLogger, type AuthStoreContext, type AuthStoreConfig, type SessionMonitorConfig, type SessionUser, type AuthStatus, } from '@eventuras/fides-auth-store';
|
|
102
|
-
export { createAuthStoreHooks, useSessionMonitor, useHeartbeat, type AuthStoreSelector, type AuthStoreActions, type HeartbeatConfig, } from '@eventuras/fides-auth-react';
|
|
103
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AAIH,OAAO,EACL,eAAe,EACf,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,6BAA6B,CAAC"}
|
package/dist/store/index.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { checkAuth, configureAuthLogger, createAuthStore, initializeAuth, startSessionMonitor } from "@eventuras/fides-auth-store";
|
|
2
|
-
import { createAuthStoreHooks, useHeartbeat, useSessionMonitor } from "@eventuras/fides-auth-react";
|
|
3
|
-
export { checkAuth, configureAuthLogger, createAuthStore, createAuthStoreHooks, initializeAuth, startSessionMonitor, useHeartbeat, useSessionMonitor };
|