@eventuras/fides-auth-next 0.1.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.
Files changed (49) hide show
  1. package/README.md +71 -0
  2. package/dist/cookies.d.ts +143 -0
  3. package/dist/cookies.d.ts.map +1 -0
  4. package/dist/cookies.js +81 -0
  5. package/dist/fides-auth/dist/build-CNL3v39v.js +977 -0
  6. package/dist/fides-auth/dist/decode_jwt-1J26fl4I.js +25 -0
  7. package/dist/fides-auth/dist/decrypt-Cahlu_6Y.js +88 -0
  8. package/dist/fides-auth/dist/deflate-koSuX7FB.js +969 -0
  9. package/dist/fides-auth/dist/logger.js +46 -0
  10. package/dist/fides-auth/dist/oauth.js +165 -0
  11. package/dist/fides-auth/dist/rate-limit.js +26 -0
  12. package/dist/fides-auth/dist/session-refresh.js +27 -0
  13. package/dist/fides-auth/dist/session-validation-BxObT3wC.js +64 -0
  14. package/dist/fides-auth/dist/silent-login.js +50 -0
  15. package/dist/fides-auth/dist/utils-ByMRF7b2.js +379 -0
  16. package/dist/index.d.ts +15 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +18 -0
  19. package/dist/oidc-callback.d.ts +46 -0
  20. package/dist/oidc-callback.d.ts.map +1 -0
  21. package/dist/oidc-callback.js +33 -0
  22. package/dist/oidc-login.d.ts +26 -0
  23. package/dist/oidc-login.d.ts.map +1 -0
  24. package/dist/oidc-login.js +20 -0
  25. package/dist/request.d.ts +3 -0
  26. package/dist/request.d.ts.map +1 -0
  27. package/dist/request.js +26 -0
  28. package/dist/session.d.ts +111 -0
  29. package/dist/session.d.ts.map +1 -0
  30. package/dist/session.js +61 -0
  31. package/dist/store/configure-logger.d.ts +15 -0
  32. package/dist/store/configure-logger.d.ts.map +1 -0
  33. package/dist/store/configure-logger.js +10 -0
  34. package/dist/store/hooks.d.ts +64 -0
  35. package/dist/store/hooks.d.ts.map +1 -0
  36. package/dist/store/hooks.js +36 -0
  37. package/dist/store/index.d.ts +107 -0
  38. package/dist/store/index.d.ts.map +1 -0
  39. package/dist/store/index.js +6 -0
  40. package/dist/store/session-monitor.d.ts +51 -0
  41. package/dist/store/session-monitor.d.ts.map +1 -0
  42. package/dist/store/session-monitor.js +49 -0
  43. package/dist/store/store.d.ts +83 -0
  44. package/dist/store/store.d.ts.map +1 -0
  45. package/dist/store/store.js +134 -0
  46. package/dist/store/use-session-monitor.d.ts +28 -0
  47. package/dist/store/use-session-monitor.d.ts.map +1 -0
  48. package/dist/store/use-session-monitor.js +13 -0
  49. package/package.json +60 -0
@@ -0,0 +1,134 @@
1
+ import { Logger as e } from "@eventuras/logger";
2
+ import { createStore as t } from "@xstate/store";
3
+ //#region src/store/store.ts
4
+ var n = {
5
+ adminRole: "Admin",
6
+ loggerNamespace: "fides:auth-store"
7
+ };
8
+ function r(r) {
9
+ let i = {
10
+ ...n,
11
+ ...r.config
12
+ }, a = e.create({
13
+ namespace: i.loggerNamespace,
14
+ context: { component: "AuthStore" }
15
+ });
16
+ return t({
17
+ context: {
18
+ user: null,
19
+ isAdmin: !1,
20
+ isAuthenticated: !1,
21
+ error: null,
22
+ lastChecked: null,
23
+ isInitializing: !0
24
+ },
25
+ on: {
26
+ initialize: () => ({
27
+ user: null,
28
+ isAdmin: !1,
29
+ isAuthenticated: !1,
30
+ error: null,
31
+ lastChecked: null,
32
+ isInitializing: !0
33
+ }),
34
+ authSuccess: (e, t) => (a.info({ user: t.user.roles }, "User authenticated"), {
35
+ user: t.user,
36
+ isAdmin: t.user.roles?.includes(i.adminRole) ?? !1,
37
+ isAuthenticated: !0,
38
+ error: null,
39
+ lastChecked: /* @__PURE__ */ new Date(),
40
+ isInitializing: !1
41
+ }),
42
+ authFailed: (e, t = {}) => (a.info("User not authenticated"), {
43
+ user: null,
44
+ isAdmin: !1,
45
+ isAuthenticated: !1,
46
+ error: t.error || null,
47
+ lastChecked: /* @__PURE__ */ new Date(),
48
+ isInitializing: !1
49
+ }),
50
+ sessionExpired: () => (a.warn("Session expired"), {
51
+ user: null,
52
+ isAdmin: !1,
53
+ isAuthenticated: !1,
54
+ error: "Session expired",
55
+ lastChecked: /* @__PURE__ */ new Date(),
56
+ isInitializing: !1
57
+ }),
58
+ logout: () => (a.info("User logged out"), {
59
+ user: null,
60
+ isAdmin: !1,
61
+ isAuthenticated: !1,
62
+ error: null,
63
+ lastChecked: /* @__PURE__ */ new Date(),
64
+ isInitializing: !1
65
+ }),
66
+ loginSuccess: (e, t) => (a.info({ user: t.user.email }, "Login successful"), {
67
+ user: t.user,
68
+ isAdmin: t.user.roles?.includes(i.adminRole) ?? !1,
69
+ isAuthenticated: !0,
70
+ error: null,
71
+ lastChecked: /* @__PURE__ */ new Date(),
72
+ isInitializing: !1
73
+ }),
74
+ updateLastChecked: (e) => ({
75
+ ...e,
76
+ lastChecked: /* @__PURE__ */ new Date()
77
+ }),
78
+ setError: (e, t) => ({
79
+ ...e,
80
+ error: t.error
81
+ }),
82
+ clearError: (e) => ({
83
+ ...e,
84
+ error: null
85
+ })
86
+ }
87
+ });
88
+ }
89
+ async function i(t, n) {
90
+ let r = e.create({
91
+ namespace: "fides:auth-store",
92
+ context: { component: "initializeAuth" }
93
+ });
94
+ r.debug("Initializing authentication"), t.send({ type: "initialize" });
95
+ try {
96
+ let e = await n();
97
+ r.debug({ authenticated: e.authenticated }, "Auth status checked"), e.authenticated && e.user ? t.send({
98
+ type: "authSuccess",
99
+ user: e.user
100
+ }) : t.send({ type: "authFailed" });
101
+ } catch (e) {
102
+ r.debug({ error: e }, "Auth check returned no session"), t.send({ type: "authFailed" });
103
+ }
104
+ }
105
+ async function a(t, n) {
106
+ let r = e.create({
107
+ namespace: "fides:auth-store",
108
+ context: { component: "checkAuth" }
109
+ });
110
+ r.debug("Checking authentication status");
111
+ try {
112
+ let e = await n();
113
+ r.debug({ authenticated: e.authenticated }, "Auth status checked"), e.authenticated && e.user ? t.send({
114
+ type: "authSuccess",
115
+ user: e.user
116
+ }) : t.send({ type: "authFailed" }), t.send({ type: "updateLastChecked" });
117
+ } catch (e) {
118
+ let n = e;
119
+ if (n?.code === "OAUTH_RESPONSE_BODY_ERROR" && n?.error === "invalid_grant") r.info("Session ended - refresh token expired or invalid"), t.send({ type: "sessionExpired" });
120
+ else {
121
+ let n = { message: e instanceof Error ? e.message : "Unknown error" };
122
+ if (e && typeof e == "object") {
123
+ let t = e;
124
+ t.code && (n.code = t.code), t.error && (n.error = t.error), t.error_description && (n.error_description = t.error_description), t.status && (n.status = t.status);
125
+ }
126
+ r.error(n, "Auth check error"), t.send({
127
+ type: "authFailed",
128
+ error: e instanceof Error ? e.message : "Unknown error"
129
+ });
130
+ }
131
+ }
132
+ }
133
+ //#endregion
134
+ export { a as checkAuth, r as createAuthStore, i as initializeAuth };
@@ -0,0 +1,28 @@
1
+ import { SessionMonitorConfig } from './session-monitor';
2
+ import { createAuthStore } from './store';
3
+ import { AuthStatus } from './types';
4
+ /**
5
+ * React hook for session monitoring with automatic cleanup
6
+ *
7
+ * @param store - The auth store to update
8
+ * @param checkAuthStatus - Function to check authentication status
9
+ * @param config - Optional configuration
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { useSessionMonitor } from '@eventuras/fides-auth-next/store';
14
+ *
15
+ * function App() {
16
+ * useSessionMonitor(authStore, checkAuthStatus, {
17
+ * interval: 30_000,
18
+ * onSessionExpired: () => {
19
+ * toast.warn('Your session has expired');
20
+ * }
21
+ * });
22
+ *
23
+ * return <div>...</div>;
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function useSessionMonitor(store: ReturnType<typeof createAuthStore>, checkAuthStatus: () => Promise<AuthStatus>, config?: SessionMonitorConfig): void;
28
+ //# sourceMappingURL=use-session-monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-session-monitor.d.ts","sourceRoot":"","sources":["../../src/store/use-session-monitor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,EACzC,eAAe,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAC1C,MAAM,GAAE,oBAAyB,GAChC,IAAI,CAIN"}
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { startSessionMonitor as e } from "./session-monitor.js";
3
+ import { useEffect as t } from "react";
4
+ //#region src/store/use-session-monitor.ts
5
+ function n(n, r, i = {}) {
6
+ t(() => e(n, r, i), [
7
+ n,
8
+ r,
9
+ i
10
+ ]);
11
+ }
12
+ //#endregion
13
+ export { n as useSessionMonitor };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@eventuras/fides-auth-next",
3
+ "version": "0.1.5",
4
+ "description": "Next.js bindings for @eventuras/fides-auth",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ },
10
+ "./session": {
11
+ "types": "./dist/session.d.ts",
12
+ "import": "./dist/session.js"
13
+ },
14
+ "./request": {
15
+ "types": "./dist/request.d.ts",
16
+ "import": "./dist/request.js"
17
+ },
18
+ "./store": {
19
+ "types": "./dist/store/index.d.ts",
20
+ "import": "./dist/store/index.js"
21
+ },
22
+ "./oidc-callback": {
23
+ "types": "./dist/oidc-callback.d.ts",
24
+ "import": "./dist/oidc-callback.js"
25
+ },
26
+ "./oidc-login": {
27
+ "types": "./dist/oidc-login.d.ts",
28
+ "import": "./dist/oidc-login.js"
29
+ }
30
+ },
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "build": "vite build",
38
+ "dev": "vite build --watch"
39
+ },
40
+ "dependencies": {
41
+ "@eventuras/fides-auth": "workspace:*",
42
+ "@eventuras/logger": "workspace:*",
43
+ "@eventuras/typescript-config": "workspace:*",
44
+ "@xstate/store": "^3.17.1"
45
+ },
46
+ "devDependencies": {
47
+ "@eventuras/vite-config": "workspace:*",
48
+ "@types/react": "^19.2.14",
49
+ "@types/react-dom": "^19.2.3",
50
+ "vite": "^8.0.3",
51
+ "xstate": "^5.30.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@xstate/react": "^5.0.0 || ^6.0.0",
55
+ "@xstate/store": "^3.11.0",
56
+ "next": "^16.0.0",
57
+ "react": "^19.0.0",
58
+ "xstate": "^5.0.0"
59
+ }
60
+ }