@eventuras/fides-auth-next 0.1.5 → 0.1.11
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/LICENSE +674 -0
- package/dist/cookies.js +192 -53
- package/dist/cookies.js.map +1 -0
- package/dist/index.js +18 -17
- package/dist/oidc-callback.js +52 -22
- package/dist/oidc-callback.js.map +1 -0
- package/dist/oidc-login.js +41 -15
- package/dist/oidc-login.js.map +1 -0
- package/dist/request.js +27 -17
- package/dist/request.js.map +1 -0
- package/dist/session.js +184 -44
- package/dist/session.js.map +1 -0
- package/dist/store/configure-logger.js +21 -6
- package/dist/store/configure-logger.js.map +1 -0
- package/dist/store/hooks.js +61 -19
- package/dist/store/hooks.js.map +1 -0
- package/dist/store/index.js +6 -6
- package/dist/store/session-monitor.js +80 -37
- package/dist/store/session-monitor.js.map +1 -0
- package/dist/store/store.js +174 -90
- package/dist/store/store.js.map +1 -0
- package/dist/store/use-session-monitor.js +35 -8
- package/dist/store/use-session-monitor.js.map +1 -0
- package/package.json +22 -13
- package/dist/fides-auth/dist/build-CNL3v39v.js +0 -977
- package/dist/fides-auth/dist/decode_jwt-1J26fl4I.js +0 -25
- package/dist/fides-auth/dist/decrypt-Cahlu_6Y.js +0 -88
- package/dist/fides-auth/dist/deflate-koSuX7FB.js +0 -969
- package/dist/fides-auth/dist/logger.js +0 -46
- package/dist/fides-auth/dist/oauth.js +0 -165
- package/dist/fides-auth/dist/rate-limit.js +0 -26
- package/dist/fides-auth/dist/session-refresh.js +0 -27
- package/dist/fides-auth/dist/session-validation-BxObT3wC.js +0 -64
- package/dist/fides-auth/dist/silent-login.js +0 -50
- package/dist/fides-auth/dist/utils-ByMRF7b2.js +0 -379
package/dist/store/store.js
CHANGED
|
@@ -1,134 +1,218 @@
|
|
|
1
|
-
import { Logger
|
|
2
|
-
import { createStore
|
|
1
|
+
import { Logger } from "@eventuras/logger";
|
|
2
|
+
import { createStore } from "@xstate/store";
|
|
3
3
|
//#region src/store/store.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values
|
|
6
|
+
*/
|
|
7
|
+
var DEFAULT_CONFIG = {
|
|
5
8
|
adminRole: "Admin",
|
|
6
9
|
loggerNamespace: "fides:auth-store"
|
|
7
10
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates an authentication store with XState Store
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration for the auth store
|
|
15
|
+
* @returns Configured XState store
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const authStore = createAuthStore({
|
|
20
|
+
* checkAuthStatus: async () => getAuthStatus(),
|
|
21
|
+
* config: {
|
|
22
|
+
* adminRole: 'Admin',
|
|
23
|
+
* loggerNamespace: 'myapp:auth',
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function createAuthStore(options) {
|
|
29
|
+
const config = {
|
|
30
|
+
...DEFAULT_CONFIG,
|
|
31
|
+
...options.config
|
|
32
|
+
};
|
|
33
|
+
const logger = Logger.create({
|
|
34
|
+
namespace: config.loggerNamespace,
|
|
14
35
|
context: { component: "AuthStore" }
|
|
15
36
|
});
|
|
16
|
-
return
|
|
37
|
+
return createStore({
|
|
17
38
|
context: {
|
|
18
39
|
user: null,
|
|
19
|
-
isAdmin:
|
|
20
|
-
isAuthenticated:
|
|
40
|
+
isAdmin: false,
|
|
41
|
+
isAuthenticated: false,
|
|
21
42
|
error: null,
|
|
22
43
|
lastChecked: null,
|
|
23
|
-
isInitializing:
|
|
44
|
+
isInitializing: true
|
|
24
45
|
},
|
|
25
46
|
on: {
|
|
47
|
+
/**
|
|
48
|
+
* Initialize authentication - check current status
|
|
49
|
+
*/
|
|
26
50
|
initialize: () => ({
|
|
27
51
|
user: null,
|
|
28
|
-
isAdmin:
|
|
29
|
-
isAuthenticated:
|
|
52
|
+
isAdmin: false,
|
|
53
|
+
isAuthenticated: false,
|
|
30
54
|
error: null,
|
|
31
55
|
lastChecked: null,
|
|
32
|
-
isInitializing:
|
|
56
|
+
isInitializing: true
|
|
33
57
|
}),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Authentication check succeeded
|
|
60
|
+
*/
|
|
61
|
+
authSuccess: (_context, event) => {
|
|
62
|
+
logger.info({ user: event.user.roles }, "User authenticated");
|
|
63
|
+
return {
|
|
64
|
+
user: event.user,
|
|
65
|
+
isAdmin: event.user.roles?.includes(config.adminRole) ?? false,
|
|
66
|
+
isAuthenticated: true,
|
|
67
|
+
error: null,
|
|
68
|
+
lastChecked: /* @__PURE__ */ new Date(),
|
|
69
|
+
isInitializing: false
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Authentication check failed - not authenticated
|
|
74
|
+
*/
|
|
75
|
+
authFailed: (_context, event = {}) => {
|
|
76
|
+
logger.info("User not authenticated");
|
|
77
|
+
return {
|
|
78
|
+
user: null,
|
|
79
|
+
isAdmin: false,
|
|
80
|
+
isAuthenticated: false,
|
|
81
|
+
error: event.error || null,
|
|
82
|
+
lastChecked: /* @__PURE__ */ new Date(),
|
|
83
|
+
isInitializing: false
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Session expired
|
|
88
|
+
*/
|
|
89
|
+
sessionExpired: () => {
|
|
90
|
+
logger.warn("Session expired");
|
|
91
|
+
return {
|
|
92
|
+
user: null,
|
|
93
|
+
isAdmin: false,
|
|
94
|
+
isAuthenticated: false,
|
|
95
|
+
error: "Session expired",
|
|
96
|
+
lastChecked: /* @__PURE__ */ new Date(),
|
|
97
|
+
isInitializing: false
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* User logged out
|
|
102
|
+
*/
|
|
103
|
+
logout: () => {
|
|
104
|
+
logger.info("User logged out");
|
|
105
|
+
return {
|
|
106
|
+
user: null,
|
|
107
|
+
isAdmin: false,
|
|
108
|
+
isAuthenticated: false,
|
|
109
|
+
error: null,
|
|
110
|
+
lastChecked: /* @__PURE__ */ new Date(),
|
|
111
|
+
isInitializing: false
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Login success
|
|
116
|
+
*/
|
|
117
|
+
loginSuccess: (_context, event) => {
|
|
118
|
+
logger.info({ user: event.user.email }, "Login successful");
|
|
119
|
+
return {
|
|
120
|
+
user: event.user,
|
|
121
|
+
isAdmin: event.user.roles?.includes(config.adminRole) ?? false,
|
|
122
|
+
isAuthenticated: true,
|
|
123
|
+
error: null,
|
|
124
|
+
lastChecked: /* @__PURE__ */ new Date(),
|
|
125
|
+
isInitializing: false
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Update last checked timestamp
|
|
130
|
+
*/
|
|
131
|
+
updateLastChecked: (context) => ({
|
|
132
|
+
...context,
|
|
76
133
|
lastChecked: /* @__PURE__ */ new Date()
|
|
77
134
|
}),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Set error
|
|
137
|
+
*/
|
|
138
|
+
setError: (context, event) => ({
|
|
139
|
+
...context,
|
|
140
|
+
error: event.error
|
|
81
141
|
}),
|
|
82
|
-
|
|
83
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Clear error
|
|
144
|
+
*/
|
|
145
|
+
clearError: (context) => ({
|
|
146
|
+
...context,
|
|
84
147
|
error: null
|
|
85
148
|
})
|
|
86
149
|
}
|
|
87
150
|
});
|
|
88
151
|
}
|
|
89
|
-
|
|
90
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Helper function to initialize auth by checking status
|
|
154
|
+
*/
|
|
155
|
+
async function initializeAuth(store, checkAuthStatus) {
|
|
156
|
+
const logger = Logger.create({
|
|
91
157
|
namespace: "fides:auth-store",
|
|
92
158
|
context: { component: "initializeAuth" }
|
|
93
159
|
});
|
|
94
|
-
|
|
160
|
+
logger.debug("Initializing authentication");
|
|
161
|
+
store.send({ type: "initialize" });
|
|
95
162
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
163
|
+
const result = await checkAuthStatus();
|
|
164
|
+
logger.debug({ authenticated: result.authenticated }, "Auth status checked");
|
|
165
|
+
if (result.authenticated && result.user) store.send({
|
|
98
166
|
type: "authSuccess",
|
|
99
|
-
user:
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
|
|
167
|
+
user: result.user
|
|
168
|
+
});
|
|
169
|
+
else store.send({ type: "authFailed" });
|
|
170
|
+
} catch (error) {
|
|
171
|
+
logger.debug({ error }, "Auth check returned no session");
|
|
172
|
+
store.send({ type: "authFailed" });
|
|
103
173
|
}
|
|
104
174
|
}
|
|
105
|
-
|
|
106
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Helper function to check auth status and update store
|
|
177
|
+
*/
|
|
178
|
+
async function checkAuth(store, checkAuthStatus) {
|
|
179
|
+
const logger = Logger.create({
|
|
107
180
|
namespace: "fides:auth-store",
|
|
108
181
|
context: { component: "checkAuth" }
|
|
109
182
|
});
|
|
110
|
-
|
|
183
|
+
logger.debug("Checking authentication status");
|
|
111
184
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
185
|
+
const result = await checkAuthStatus();
|
|
186
|
+
logger.debug({ authenticated: result.authenticated }, "Auth status checked");
|
|
187
|
+
if (result.authenticated && result.user) store.send({
|
|
114
188
|
type: "authSuccess",
|
|
115
|
-
user:
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
189
|
+
user: result.user
|
|
190
|
+
});
|
|
191
|
+
else store.send({ type: "authFailed" });
|
|
192
|
+
store.send({ type: "updateLastChecked" });
|
|
193
|
+
} catch (error) {
|
|
194
|
+
const err = error;
|
|
195
|
+
if (err?.code === "OAUTH_RESPONSE_BODY_ERROR" && err?.error === "invalid_grant") {
|
|
196
|
+
logger.info("Session ended - refresh token expired or invalid");
|
|
197
|
+
store.send({ type: "sessionExpired" });
|
|
198
|
+
} else {
|
|
199
|
+
const errorDetails = { message: error instanceof Error ? error.message : "Unknown error" };
|
|
200
|
+
if (error && typeof error === "object") {
|
|
201
|
+
const oauthError = error;
|
|
202
|
+
if (oauthError.code) errorDetails.code = oauthError.code;
|
|
203
|
+
if (oauthError.error) errorDetails.error = oauthError.error;
|
|
204
|
+
if (oauthError.error_description) errorDetails.error_description = oauthError.error_description;
|
|
205
|
+
if (oauthError.status) errorDetails.status = oauthError.status;
|
|
125
206
|
}
|
|
126
|
-
|
|
207
|
+
logger.error(errorDetails, "Auth check error");
|
|
208
|
+
store.send({
|
|
127
209
|
type: "authFailed",
|
|
128
|
-
error:
|
|
210
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
129
211
|
});
|
|
130
212
|
}
|
|
131
213
|
}
|
|
132
214
|
}
|
|
133
215
|
//#endregion
|
|
134
|
-
export {
|
|
216
|
+
export { checkAuth, createAuthStore, initializeAuth };
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","names":[],"sources":["../../src/store/store.ts"],"sourcesContent":["import { createStore } from '@xstate/store';\nimport { Logger } from '@eventuras/logger';\nimport type { SessionUser, AuthStatus } from './types';\n\n/**\n * Authentication store context\n */\nexport type AuthStoreContext = {\n user: SessionUser | null;\n isAdmin: boolean;\n isAuthenticated: boolean;\n error: string | null;\n lastChecked: Date | null;\n isInitializing: boolean;\n};\n\n/**\n * Configuration for the auth store\n */\nexport type AuthStoreConfig = {\n /**\n * Function to check current authentication status\n */\n checkAuthStatus: () => Promise<AuthStatus>;\n\n /**\n * Optional configuration\n */\n config?: {\n /**\n * Role name that indicates admin access\n * @default 'Admin'\n */\n adminRole?: string;\n\n /**\n * Namespace for logger\n * @default 'fides-auth-next:store'\n */\n loggerNamespace?: string;\n };\n};\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG = {\n adminRole: 'Admin',\n loggerNamespace: 'fides:auth-store',\n};\n\n/**\n * Creates an authentication store with XState Store\n *\n * @param options - Configuration for the auth store\n * @returns Configured XState store\n *\n * @example\n * ```typescript\n * const authStore = createAuthStore({\n * checkAuthStatus: async () => getAuthStatus(),\n * config: {\n * adminRole: 'Admin',\n * loggerNamespace: 'myapp:auth',\n * }\n * });\n * ```\n */\nexport function createAuthStore(options: AuthStoreConfig) {\n const config = { ...DEFAULT_CONFIG, ...options.config };\n const logger = Logger.create({\n namespace: config.loggerNamespace,\n context: { component: 'AuthStore' },\n });\n\n /**\n * Initial context values\n */\n const initialContext: AuthStoreContext = {\n user: null,\n isAdmin: false,\n isAuthenticated: false,\n error: null,\n lastChecked: null,\n isInitializing: true,\n };\n\n /**\n * Create the store with events\n */\n const store = createStore(\n {\n context: initialContext,\n on: {\n /**\n * Initialize authentication - check current status\n */\n initialize: () => ({\n user: null,\n isAdmin: false,\n isAuthenticated: false,\n error: null,\n lastChecked: null,\n isInitializing: true,\n }),\n\n /**\n * Authentication check succeeded\n */\n authSuccess: (_context: AuthStoreContext, event: { user: SessionUser; }) => {\n logger.info({ user: event.user.roles }, 'User authenticated');\n return {\n user: event.user,\n isAdmin: event.user.roles?.includes(config.adminRole) ?? false,\n isAuthenticated: true,\n error: null,\n lastChecked: new Date(),\n isInitializing: false,\n };\n },\n\n /**\n * Authentication check failed - not authenticated\n */\n authFailed: (_context: AuthStoreContext, event: { error?: string; } = {}) => {\n logger.info('User not authenticated');\n return {\n user: null,\n isAdmin: false,\n isAuthenticated: false,\n error: event.error || null,\n lastChecked: new Date(),\n isInitializing: false,\n };\n },\n\n /**\n * Session expired\n */\n sessionExpired: () => {\n logger.warn('Session expired');\n return {\n user: null,\n isAdmin: false,\n isAuthenticated: false,\n error: 'Session expired',\n lastChecked: new Date(),\n isInitializing: false,\n };\n },\n\n /**\n * User logged out\n */\n logout: () => {\n logger.info('User logged out');\n return {\n user: null,\n isAdmin: false,\n isAuthenticated: false,\n error: null,\n lastChecked: new Date(),\n isInitializing: false,\n };\n },\n\n /**\n * Login success\n */\n loginSuccess: (_context: AuthStoreContext, event: { user: SessionUser; }) => {\n logger.info({ user: event.user.email }, 'Login successful');\n return {\n user: event.user,\n isAdmin: event.user.roles?.includes(config.adminRole) ?? false,\n isAuthenticated: true,\n error: null,\n lastChecked: new Date(),\n isInitializing: false,\n };\n },\n\n /**\n * Update last checked timestamp\n */\n updateLastChecked: (context: AuthStoreContext) => ({\n ...context,\n lastChecked: new Date(),\n }),\n\n /**\n * Set error\n */\n setError: (context: AuthStoreContext, event: { error: string; }) => ({\n ...context,\n error: event.error,\n }),\n\n /**\n * Clear error\n */\n clearError: (context: AuthStoreContext) => ({\n ...context,\n error: null,\n }),\n },\n }\n );\n\n return store;\n}\n\n/**\n * Helper function to initialize auth by checking status\n */\nexport async function initializeAuth(\n store: ReturnType<typeof createAuthStore>,\n checkAuthStatus: () => Promise<AuthStatus>\n) {\n const logger = Logger.create({\n namespace: 'fides:auth-store',\n context: { component: 'initializeAuth' },\n });\n\n logger.debug('Initializing authentication');\n store.send({ type: 'initialize' });\n\n try {\n const result = await checkAuthStatus();\n logger.debug({ authenticated: result.authenticated }, 'Auth status checked');\n\n if (result.authenticated && result.user) {\n store.send({ type: 'authSuccess', user: result.user });\n } else {\n store.send({ type: 'authFailed' });\n }\n } catch (error) {\n logger.debug({ error }, 'Auth check returned no session');\n store.send({ type: 'authFailed' });\n }\n}\n\n/**\n * Helper function to check auth status and update store\n */\nexport async function checkAuth(\n store: ReturnType<typeof createAuthStore>,\n checkAuthStatus: () => Promise<AuthStatus>\n) {\n const logger = Logger.create({\n namespace: 'fides:auth-store',\n context: { component: 'checkAuth' },\n });\n\n logger.debug('Checking authentication status');\n\n try {\n const result = await checkAuthStatus();\n logger.debug({ authenticated: result.authenticated }, 'Auth status checked');\n\n if (result.authenticated && result.user) {\n store.send({ type: 'authSuccess', user: result.user });\n } else {\n store.send({ type: 'authFailed' });\n }\n\n store.send({ type: 'updateLastChecked' });\n } catch (error) {\n // Check if this is an expected invalid_grant error (expired refresh token)\n const err = error as { code?: string; error?: string; error_description?: string; };\n const isInvalidGrant =\n err?.code === 'OAUTH_RESPONSE_BODY_ERROR' && err?.error === 'invalid_grant';\n\n if (isInvalidGrant) {\n // This is expected during logout or session expiry - log at info level\n logger.info('Session ended - refresh token expired or invalid');\n store.send({ type: 'sessionExpired' });\n } else {\n // Unexpected error during auth check - log with details\n const errorDetails: Record<string, unknown> = {\n message: error instanceof Error ? error.message : 'Unknown error',\n };\n\n // Extract OAuth error details if present\n if (error && typeof error === 'object') {\n const oauthError = error as any;\n if (oauthError.code) errorDetails.code = oauthError.code;\n if (oauthError.error) errorDetails.error = oauthError.error;\n if (oauthError.error_description)\n errorDetails.error_description = oauthError.error_description;\n if (oauthError.status) errorDetails.status = oauthError.status;\n }\n\n logger.error(errorDetails, 'Auth check error');\n store.send({\n type: 'authFailed',\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n}\n"],"mappings":";;;;;;A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C,OAAM,KAAK;GAAE,MAAM;GAAe,MAAM,OAAO;GAAM,CAAC;MAEtD,OAAM,KAAK,EAAE,MAAM,cAAc,CAAC;AAGpC,QAAM,KAAK,EAAE,MAAM,qBAAqB,CAAC;UAClC,OAAO;EAEd,MAAM,MAAM;AAIZ,MAFE,KAAK,SAAS,+BAA+B,KAAK,UAAU,iBAE1C;AAElB,UAAO,KAAK,mDAAmD;AAC/D,SAAM,KAAK,EAAE,MAAM,kBAAkB,CAAC;SACjC;GAEL,MAAM,eAAwC,EAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,iBACnD;AAGD,OAAI,SAAS,OAAO,UAAU,UAAU;IACtC,MAAM,aAAa;AACnB,QAAI,WAAW,KAAM,cAAa,OAAO,WAAW;AACpD,QAAI,WAAW,MAAO,cAAa,QAAQ,WAAW;AACtD,QAAI,WAAW,kBACb,cAAa,oBAAoB,WAAW;AAC9C,QAAI,WAAW,OAAQ,cAAa,SAAS,WAAW;;AAG1D,UAAO,MAAM,cAAc,mBAAmB;AAC9C,SAAM,KAAK;IACT,MAAM;IACN,OAAO,iBAAiB,QAAQ,MAAM,UAAU;IACjD,CAAC"}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { startSessionMonitor
|
|
3
|
-
import { useEffect
|
|
2
|
+
import { startSessionMonitor } from "./session-monitor.js";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
4
|
//#region src/store/use-session-monitor.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* React hook for session monitoring with automatic cleanup
|
|
7
|
+
*
|
|
8
|
+
* @param store - The auth store to update
|
|
9
|
+
* @param checkAuthStatus - Function to check authentication status
|
|
10
|
+
* @param config - Optional configuration
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { useSessionMonitor } from '@eventuras/fides-auth-next/store';
|
|
15
|
+
*
|
|
16
|
+
* function App() {
|
|
17
|
+
* useSessionMonitor(authStore, checkAuthStatus, {
|
|
18
|
+
* interval: 30_000,
|
|
19
|
+
* onSessionExpired: () => {
|
|
20
|
+
* toast.warn('Your session has expired');
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* return <div>...</div>;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function useSessionMonitor(store, checkAuthStatus, config = {}) {
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return startSessionMonitor(store, checkAuthStatus, config);
|
|
31
|
+
}, [
|
|
32
|
+
store,
|
|
33
|
+
checkAuthStatus,
|
|
34
|
+
config
|
|
10
35
|
]);
|
|
11
36
|
}
|
|
12
37
|
//#endregion
|
|
13
|
-
export {
|
|
38
|
+
export { useSessionMonitor };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=use-session-monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-session-monitor.js","names":[],"sources":["../../src/store/use-session-monitor.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { startSessionMonitor, type SessionMonitorConfig } from './session-monitor';\nimport type { createAuthStore } from './store';\nimport type { AuthStatus } from './types';\n\n/**\n * React hook for session monitoring with automatic cleanup\n *\n * @param store - The auth store to update\n * @param checkAuthStatus - Function to check authentication status\n * @param config - Optional configuration\n *\n * @example\n * ```typescript\n * import { useSessionMonitor } from '@eventuras/fides-auth-next/store';\n *\n * function App() {\n * useSessionMonitor(authStore, checkAuthStatus, {\n * interval: 30_000,\n * onSessionExpired: () => {\n * toast.warn('Your session has expired');\n * }\n * });\n *\n * return <div>...</div>;\n * }\n * ```\n */\nexport function useSessionMonitor(\n store: ReturnType<typeof createAuthStore>,\n checkAuthStatus: () => Promise<AuthStatus>,\n config: SessionMonitorConfig = {}\n): void {\n useEffect(() => {\n return startSessionMonitor(store, checkAuthStatus, config);\n }, [store, checkAuthStatus, config]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBACd,OACA,iBACA,SAA+B,EAAE,EAC3B;AACN,iBAAgB;AACd,SAAO,oBAAoB,OAAO,iBAAiB,OAAO;IACzD;EAAC;EAAO;EAAiB;EAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/fides-auth-next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Next.js bindings for @eventuras/fides-auth",
|
|
5
|
+
"homepage": "https://github.com/losol/eventuras/tree/main/libs/fides-auth-next#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/losol/eventuras/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/losol/eventuras.git",
|
|
12
|
+
"directory": "libs/fides-auth-next"
|
|
13
|
+
},
|
|
5
14
|
"exports": {
|
|
6
15
|
".": {
|
|
7
16
|
"types": "./dist/index.d.ts",
|
|
@@ -33,22 +42,18 @@
|
|
|
33
42
|
"files": [
|
|
34
43
|
"dist"
|
|
35
44
|
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "vite build",
|
|
38
|
-
"dev": "vite build --watch"
|
|
39
|
-
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@eventuras/
|
|
43
|
-
"@eventuras/
|
|
44
|
-
"@xstate/store": "^3.17.1"
|
|
46
|
+
"@xstate/store": "^3.17.1",
|
|
47
|
+
"@eventuras/fides-auth": "0.7.0",
|
|
48
|
+
"@eventuras/logger": "0.8.1"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
|
-
"@eventuras/vite-config": "workspace:*",
|
|
48
51
|
"@types/react": "^19.2.14",
|
|
49
52
|
"@types/react-dom": "^19.2.3",
|
|
50
|
-
"vite": "^8.0.
|
|
51
|
-
"xstate": "^5.30.0"
|
|
53
|
+
"vite": "^8.0.8",
|
|
54
|
+
"xstate": "^5.30.0",
|
|
55
|
+
"@eventuras/typescript-config": "1.0.0",
|
|
56
|
+
"@eventuras/vite-config": "0.2.2"
|
|
52
57
|
},
|
|
53
58
|
"peerDependencies": {
|
|
54
59
|
"@xstate/react": "^5.0.0 || ^6.0.0",
|
|
@@ -56,5 +61,9 @@
|
|
|
56
61
|
"next": "^16.0.0",
|
|
57
62
|
"react": "^19.0.0",
|
|
58
63
|
"xstate": "^5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "vite build",
|
|
67
|
+
"dev": "vite build --watch"
|
|
59
68
|
}
|
|
60
|
-
}
|
|
69
|
+
}
|