@oxyhq/services 5.5.7 → 5.5.9
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/lib/commonjs/core/index.js +13 -13
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +480 -87
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAuthFetch.js +80 -45
- package/lib/commonjs/ui/hooks/useAuthFetch.js.map +1 -1
- package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/module/core/index.js +13 -6
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +480 -87
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/hooks/useAuthFetch.js +80 -45
- package/lib/module/ui/hooks/useAuthFetch.js.map +1 -1
- package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/typescript/core/index.d.ts +7 -6
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +12 -7
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useAuthFetch.d.ts +10 -4
- package/lib/typescript/ui/hooks/useAuthFetch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/backend-middleware.test.ts +209 -0
- package/src/__tests__/ui/hooks/authfetch-integration.test.ts +197 -0
- package/src/__tests__/ui/hooks/backward-compatibility.test.ts +159 -0
- package/src/__tests__/ui/hooks/real-world-scenarios.test.ts +224 -0
- package/src/__tests__/ui/hooks/url-resolution.test.ts +129 -0
- package/src/__tests__/ui/hooks/useAuthFetch-separation.test.ts +69 -0
- package/src/__tests__/ui/hooks/useAuthFetch.test.ts +70 -0
- package/src/core/index.ts +13 -7
- package/src/ui/context/OxyContext.tsx +536 -99
- package/src/ui/hooks/useAuthFetch.ts +81 -47
- package/src/ui/screens/SessionManagementScreen.tsx +9 -9
- package/lib/commonjs/core/AuthManager.js +0 -378
- package/lib/commonjs/core/AuthManager.js.map +0 -1
- package/lib/module/core/AuthManager.js +0 -373
- package/lib/module/core/AuthManager.js.map +0 -1
- package/lib/typescript/core/AuthManager.d.ts +0 -100
- package/lib/typescript/core/AuthManager.d.ts.map +0 -1
- package/src/core/AuthManager.ts +0 -389
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Centralized Authentication Manager
|
|
5
|
-
*
|
|
6
|
-
* Single source of truth for all authentication operations
|
|
7
|
-
* Handles both JWT and session-based authentication seamlessly
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export class AuthManager {
|
|
11
|
-
currentState = {
|
|
12
|
-
isAuthenticated: false,
|
|
13
|
-
accessToken: null,
|
|
14
|
-
user: null,
|
|
15
|
-
activeSessionId: null,
|
|
16
|
-
sessions: [],
|
|
17
|
-
isLoading: false,
|
|
18
|
-
error: null
|
|
19
|
-
};
|
|
20
|
-
constructor(config) {
|
|
21
|
-
this.oxyServices = config.oxyServices;
|
|
22
|
-
this.onStateChange = config.onStateChange;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get current authentication state
|
|
27
|
-
*/
|
|
28
|
-
getState() {
|
|
29
|
-
return {
|
|
30
|
-
...this.currentState
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get access token for API calls
|
|
36
|
-
* This is the ONLY method that should be used to get tokens
|
|
37
|
-
*/
|
|
38
|
-
async getAccessToken() {
|
|
39
|
-
console.log('[AuthManager] getAccessToken called');
|
|
40
|
-
console.log('[AuthManager] Current state:', {
|
|
41
|
-
isAuthenticated: this.currentState.isAuthenticated,
|
|
42
|
-
activeSessionId: this.currentState.activeSessionId,
|
|
43
|
-
hasUser: !!this.currentState.user,
|
|
44
|
-
cachedToken: !!this.currentState.accessToken
|
|
45
|
-
});
|
|
46
|
-
try {
|
|
47
|
-
// If we have a cached token in state, return it
|
|
48
|
-
if (this.currentState.accessToken) {
|
|
49
|
-
console.log('[AuthManager] Returning cached token from state');
|
|
50
|
-
return this.currentState.accessToken;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// If we already have a valid JWT token in service, return it
|
|
54
|
-
let token = this.oxyServices.getAccessToken();
|
|
55
|
-
if (token) {
|
|
56
|
-
console.log('[AuthManager] Found token in OxyServices');
|
|
57
|
-
// Cache it in our state for consistency
|
|
58
|
-
this.updateState({
|
|
59
|
-
accessToken: token
|
|
60
|
-
});
|
|
61
|
-
return token;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// If we have an active session, get token from session
|
|
65
|
-
if (this.currentState.activeSessionId) {
|
|
66
|
-
console.log('[AuthManager] Getting token from session:', this.currentState.activeSessionId);
|
|
67
|
-
const tokenData = await this.oxyServices.getTokenBySession(this.currentState.activeSessionId);
|
|
68
|
-
token = tokenData.accessToken;
|
|
69
|
-
|
|
70
|
-
// Cache it both in service and state
|
|
71
|
-
this.oxyServices.setTokens(token, '');
|
|
72
|
-
this.updateState({
|
|
73
|
-
accessToken: token
|
|
74
|
-
});
|
|
75
|
-
console.log('[AuthManager] Successfully retrieved and cached token from session');
|
|
76
|
-
return token;
|
|
77
|
-
}
|
|
78
|
-
console.warn('[AuthManager] No way to get access token - not authenticated or no session');
|
|
79
|
-
return null;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('[AuthManager] Failed to get access token:', error);
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Login with username/password
|
|
88
|
-
*/
|
|
89
|
-
async login(username, password, deviceName) {
|
|
90
|
-
this.updateState({
|
|
91
|
-
isLoading: true,
|
|
92
|
-
error: null
|
|
93
|
-
});
|
|
94
|
-
try {
|
|
95
|
-
// Use secure session login
|
|
96
|
-
const response = await this.oxyServices.secureLogin(username, password, deviceName);
|
|
97
|
-
|
|
98
|
-
// Get and cache the access token
|
|
99
|
-
const tokenData = await this.oxyServices.getTokenBySession(response.sessionId);
|
|
100
|
-
this.oxyServices.setTokens(tokenData.accessToken, '');
|
|
101
|
-
|
|
102
|
-
// Load full user data
|
|
103
|
-
const user = await this.oxyServices.getUserBySession(response.sessionId);
|
|
104
|
-
|
|
105
|
-
// Load sessions list
|
|
106
|
-
const sessions = await this.oxyServices.getSessionsBySessionId(response.sessionId);
|
|
107
|
-
this.updateState({
|
|
108
|
-
isAuthenticated: true,
|
|
109
|
-
accessToken: tokenData.accessToken,
|
|
110
|
-
user,
|
|
111
|
-
activeSessionId: response.sessionId,
|
|
112
|
-
sessions,
|
|
113
|
-
isLoading: false,
|
|
114
|
-
error: null
|
|
115
|
-
});
|
|
116
|
-
} catch (error) {
|
|
117
|
-
this.updateState({
|
|
118
|
-
isLoading: false,
|
|
119
|
-
error: error.message || 'Login failed'
|
|
120
|
-
});
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Sign up new user
|
|
127
|
-
*/
|
|
128
|
-
async signUp(username, email, password) {
|
|
129
|
-
this.updateState({
|
|
130
|
-
isLoading: true,
|
|
131
|
-
error: null
|
|
132
|
-
});
|
|
133
|
-
try {
|
|
134
|
-
// Create account
|
|
135
|
-
await this.oxyServices.signUp(username, email, password);
|
|
136
|
-
|
|
137
|
-
// Auto-login after signup
|
|
138
|
-
await this.login(username, password);
|
|
139
|
-
} catch (error) {
|
|
140
|
-
this.updateState({
|
|
141
|
-
isLoading: false,
|
|
142
|
-
error: error.message || 'Sign up failed'
|
|
143
|
-
});
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Logout current session or specific session
|
|
150
|
-
*/
|
|
151
|
-
async logout(targetSessionId) {
|
|
152
|
-
if (!this.currentState.activeSessionId) return;
|
|
153
|
-
const sessionToLogout = targetSessionId || this.currentState.activeSessionId;
|
|
154
|
-
try {
|
|
155
|
-
await this.oxyServices.logoutSecureSession(this.currentState.activeSessionId, sessionToLogout);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
console.warn('[AuthManager] Logout API call failed:', error);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// If logging out current session, clear all state
|
|
161
|
-
if (sessionToLogout === this.currentState.activeSessionId) {
|
|
162
|
-
this.clearAuthState();
|
|
163
|
-
} else {
|
|
164
|
-
// Just remove the specific session from the list
|
|
165
|
-
const updatedSessions = this.currentState.sessions.filter(s => s.sessionId !== sessionToLogout);
|
|
166
|
-
this.updateState({
|
|
167
|
-
sessions: updatedSessions
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Initialize authentication from stored data
|
|
174
|
-
*/
|
|
175
|
-
async initialize(activeSessionId) {
|
|
176
|
-
if (!activeSessionId) {
|
|
177
|
-
this.clearAuthState();
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
this.updateState({
|
|
181
|
-
isLoading: true,
|
|
182
|
-
error: null
|
|
183
|
-
});
|
|
184
|
-
try {
|
|
185
|
-
// Validate the session
|
|
186
|
-
const validation = await this.oxyServices.validateSession(activeSessionId);
|
|
187
|
-
if (!validation.valid) {
|
|
188
|
-
this.clearAuthState();
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Get access token
|
|
193
|
-
const tokenData = await this.oxyServices.getTokenBySession(activeSessionId);
|
|
194
|
-
this.oxyServices.setTokens(tokenData.accessToken, '');
|
|
195
|
-
|
|
196
|
-
// Load user data
|
|
197
|
-
const user = await this.oxyServices.getUserBySession(activeSessionId);
|
|
198
|
-
|
|
199
|
-
// Load sessions list
|
|
200
|
-
const sessions = await this.oxyServices.getSessionsBySessionId(activeSessionId);
|
|
201
|
-
this.updateState({
|
|
202
|
-
isAuthenticated: true,
|
|
203
|
-
accessToken: tokenData.accessToken,
|
|
204
|
-
user,
|
|
205
|
-
activeSessionId,
|
|
206
|
-
sessions,
|
|
207
|
-
isLoading: false,
|
|
208
|
-
error: null
|
|
209
|
-
});
|
|
210
|
-
} catch (error) {
|
|
211
|
-
console.error('[AuthManager] Initialization failed:', error);
|
|
212
|
-
this.clearAuthState();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Refresh current token
|
|
218
|
-
*/
|
|
219
|
-
async refreshToken() {
|
|
220
|
-
if (!this.currentState.activeSessionId) {
|
|
221
|
-
throw new Error('No active session to refresh');
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
const tokenData = await this.oxyServices.getTokenBySession(this.currentState.activeSessionId);
|
|
225
|
-
this.oxyServices.setTokens(tokenData.accessToken, '');
|
|
226
|
-
this.updateState({
|
|
227
|
-
accessToken: tokenData.accessToken
|
|
228
|
-
});
|
|
229
|
-
} catch (error) {
|
|
230
|
-
console.error('[AuthManager] Token refresh failed:', error);
|
|
231
|
-
this.clearAuthState();
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Check if user is authenticated
|
|
238
|
-
*/
|
|
239
|
-
isAuthenticated() {
|
|
240
|
-
const result = this.currentState.isAuthenticated;
|
|
241
|
-
console.log('[AuthManager] isAuthenticated check:', result);
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Get current user
|
|
247
|
-
*/
|
|
248
|
-
getCurrentUser() {
|
|
249
|
-
return this.currentState.user;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Get current session ID
|
|
254
|
-
*/
|
|
255
|
-
getActiveSessionId() {
|
|
256
|
-
return this.currentState.activeSessionId;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Get base URL for API calls
|
|
261
|
-
*/
|
|
262
|
-
getBaseURL() {
|
|
263
|
-
return this.oxyServices.getBaseURL();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Refresh sessions list
|
|
268
|
-
*/
|
|
269
|
-
async refreshSessions() {
|
|
270
|
-
if (!this.currentState.activeSessionId) return;
|
|
271
|
-
try {
|
|
272
|
-
const sessions = await this.oxyServices.getSessionsBySessionId(this.currentState.activeSessionId);
|
|
273
|
-
this.updateState({
|
|
274
|
-
sessions
|
|
275
|
-
});
|
|
276
|
-
} catch (error) {
|
|
277
|
-
console.error('[AuthManager] Failed to refresh sessions:', error);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Get current sessions
|
|
283
|
-
*/
|
|
284
|
-
getSessions() {
|
|
285
|
-
return this.currentState.sessions;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Switch to a different session
|
|
290
|
-
*/
|
|
291
|
-
async switchSession(sessionId) {
|
|
292
|
-
if (sessionId === this.currentState.activeSessionId) return;
|
|
293
|
-
this.updateState({
|
|
294
|
-
isLoading: true,
|
|
295
|
-
error: null
|
|
296
|
-
});
|
|
297
|
-
try {
|
|
298
|
-
// Get access token for this session
|
|
299
|
-
const tokenData = await this.oxyServices.getTokenBySession(sessionId);
|
|
300
|
-
this.oxyServices.setTokens(tokenData.accessToken, '');
|
|
301
|
-
|
|
302
|
-
// Load user data
|
|
303
|
-
const user = await this.oxyServices.getUserBySession(sessionId);
|
|
304
|
-
this.updateState({
|
|
305
|
-
activeSessionId: sessionId,
|
|
306
|
-
accessToken: tokenData.accessToken,
|
|
307
|
-
user,
|
|
308
|
-
isLoading: false
|
|
309
|
-
});
|
|
310
|
-
} catch (error) {
|
|
311
|
-
console.error('[AuthManager] Switch session failed:', error);
|
|
312
|
-
this.updateState({
|
|
313
|
-
isLoading: false,
|
|
314
|
-
error: 'Failed to switch session'
|
|
315
|
-
});
|
|
316
|
-
throw error;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Remove a session (alias for logout with sessionId)
|
|
322
|
-
*/
|
|
323
|
-
async removeSession(sessionId) {
|
|
324
|
-
await this.logout(sessionId);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Logout all sessions
|
|
329
|
-
*/
|
|
330
|
-
async logoutAll() {
|
|
331
|
-
if (!this.currentState.activeSessionId) {
|
|
332
|
-
throw new Error('No active session found');
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
await this.oxyServices.logoutAllSecureSessions(this.currentState.activeSessionId);
|
|
336
|
-
this.clearAuthState();
|
|
337
|
-
} catch (error) {
|
|
338
|
-
console.error('[AuthManager] Logout all failed:', error);
|
|
339
|
-
throw error;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Clear authentication state
|
|
345
|
-
*/
|
|
346
|
-
clearAuthState() {
|
|
347
|
-
this.oxyServices.setTokens('', ''); // Clear tokens from service
|
|
348
|
-
|
|
349
|
-
this.updateState({
|
|
350
|
-
isAuthenticated: false,
|
|
351
|
-
accessToken: null,
|
|
352
|
-
user: null,
|
|
353
|
-
activeSessionId: null,
|
|
354
|
-
sessions: [],
|
|
355
|
-
isLoading: false,
|
|
356
|
-
error: null
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Update state and notify listeners
|
|
362
|
-
*/
|
|
363
|
-
updateState(updates) {
|
|
364
|
-
this.currentState = {
|
|
365
|
-
...this.currentState,
|
|
366
|
-
...updates
|
|
367
|
-
};
|
|
368
|
-
if (this.onStateChange) {
|
|
369
|
-
this.onStateChange(this.currentState);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
//# sourceMappingURL=AuthManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AuthManager","currentState","isAuthenticated","accessToken","user","activeSessionId","sessions","isLoading","error","constructor","config","oxyServices","onStateChange","getState","getAccessToken","console","log","hasUser","cachedToken","token","updateState","tokenData","getTokenBySession","setTokens","warn","login","username","password","deviceName","response","secureLogin","sessionId","getUserBySession","getSessionsBySessionId","message","signUp","email","logout","targetSessionId","sessionToLogout","logoutSecureSession","clearAuthState","updatedSessions","filter","s","initialize","validation","validateSession","valid","refreshToken","Error","result","getCurrentUser","getActiveSessionId","getBaseURL","refreshSessions","getSessions","switchSession","removeSession","logoutAll","logoutAllSecureSessions","updates"],"sourceRoot":"../../../src","sources":["core/AuthManager.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAmBA,OAAO,MAAMA,WAAW,CAAC;EAGfC,YAAY,GAAc;IAChCC,eAAe,EAAE,KAAK;IACtBC,WAAW,EAAE,IAAI;IACjBC,IAAI,EAAE,IAAI;IACVC,eAAe,EAAE,IAAI;IACrBC,QAAQ,EAAE,EAAE;IACZC,SAAS,EAAE,KAAK;IAChBC,KAAK,EAAE;EACT,CAAC;EAEDC,WAAWA,CAACC,MAAkB,EAAE;IAC9B,IAAI,CAACC,WAAW,GAAGD,MAAM,CAACC,WAAW;IACrC,IAAI,CAACC,aAAa,GAAGF,MAAM,CAACE,aAAa;EAC3C;;EAEA;AACF;AACA;EACEC,QAAQA,CAAA,EAAc;IACpB,OAAO;MAAE,GAAG,IAAI,CAACZ;IAAa,CAAC;EACjC;;EAEA;AACF;AACA;AACA;EACE,MAAMa,cAAcA,CAAA,EAA2B;IAC7CC,OAAO,CAACC,GAAG,CAAC,qCAAqC,CAAC;IAClDD,OAAO,CAACC,GAAG,CAAC,8BAA8B,EAAE;MAC1Cd,eAAe,EAAE,IAAI,CAACD,YAAY,CAACC,eAAe;MAClDG,eAAe,EAAE,IAAI,CAACJ,YAAY,CAACI,eAAe;MAClDY,OAAO,EA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AI6C,KAAK,CAAC,yBAAyB,CAAC;IAC5C;IAEA,IAAI;MACF,MAAM,IAAI,CAACvC,WAAW,CAACiD,uBAAuB,CAAC,IAAI,CAAC3D,YAAY,CAACI,eAAe,CAAC;MACjF,IAAI,CAACoC,cAAc,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOjC,KAAK,EAAE;MACdO,OAAO,CAACP,KAAK,CAAC,kCAAkC,EAAEA,KAAK,CAAC;MACxD,MAAMA,KAAK;IACb;EACF;;EAEA;AACF;AACA;EACUiC,cAAcA,CAAA,EAAS;IAC7B,IAAI,CAAC9B,WAAW,CAACY,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;;IAEpC,IAAI,CAACH,WAAW,CAAC;MACflB,eAAe,EAAE,KAAK;MACtBC,WAAW,EAAE,IAAI;MACjBC,IAAI,EAAE,IAAI;MACVC,eAAe,EAAE,IAAI;MACrBC,QAAQ,EAAE,EAAE;MACZC,SAAS,EAAE,KAAK;MAChBC,KAAK,EAAE;IACT,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACUY,WAAWA,CAACyC,OAA2B,EAAQ;IACrD,IAAI,CAAC5D,YAAY,GAAG;MAAE,GAAG,IAAI,CAACA,YAAY;MAAE,GAAG4D;IAAQ,CAAC;IAExD,IAAI,IAAI,CAACjD,aAAa,EAAE;MACtB,IAAI,CAACA,aAAa,CAAC,IAAI,CAACX,YAAY,CAAC;IACvC;EACF;AACF","ignoreList":[]}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized Authentication Manager
|
|
3
|
-
*
|
|
4
|
-
* Single source of truth for all authentication operations
|
|
5
|
-
* Handles both JWT and session-based authentication seamlessly
|
|
6
|
-
*/
|
|
7
|
-
import { OxyServices } from './index';
|
|
8
|
-
export interface AuthState {
|
|
9
|
-
isAuthenticated: boolean;
|
|
10
|
-
accessToken: string | null;
|
|
11
|
-
user: any | null;
|
|
12
|
-
activeSessionId: string | null;
|
|
13
|
-
sessions: any[];
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
error: string | null;
|
|
16
|
-
}
|
|
17
|
-
export interface AuthConfig {
|
|
18
|
-
oxyServices: OxyServices;
|
|
19
|
-
onStateChange?: (state: AuthState) => void;
|
|
20
|
-
}
|
|
21
|
-
export declare class AuthManager {
|
|
22
|
-
private oxyServices;
|
|
23
|
-
private onStateChange?;
|
|
24
|
-
private currentState;
|
|
25
|
-
constructor(config: AuthConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Get current authentication state
|
|
28
|
-
*/
|
|
29
|
-
getState(): AuthState;
|
|
30
|
-
/**
|
|
31
|
-
* Get access token for API calls
|
|
32
|
-
* This is the ONLY method that should be used to get tokens
|
|
33
|
-
*/
|
|
34
|
-
getAccessToken(): Promise<string | null>;
|
|
35
|
-
/**
|
|
36
|
-
* Login with username/password
|
|
37
|
-
*/
|
|
38
|
-
login(username: string, password: string, deviceName?: string): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Sign up new user
|
|
41
|
-
*/
|
|
42
|
-
signUp(username: string, email: string, password: string): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Logout current session or specific session
|
|
45
|
-
*/
|
|
46
|
-
logout(targetSessionId?: string): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Initialize authentication from stored data
|
|
49
|
-
*/
|
|
50
|
-
initialize(activeSessionId: string | null): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Refresh current token
|
|
53
|
-
*/
|
|
54
|
-
refreshToken(): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Check if user is authenticated
|
|
57
|
-
*/
|
|
58
|
-
isAuthenticated(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Get current user
|
|
61
|
-
*/
|
|
62
|
-
getCurrentUser(): any | null;
|
|
63
|
-
/**
|
|
64
|
-
* Get current session ID
|
|
65
|
-
*/
|
|
66
|
-
getActiveSessionId(): string | null;
|
|
67
|
-
/**
|
|
68
|
-
* Get base URL for API calls
|
|
69
|
-
*/
|
|
70
|
-
getBaseURL(): string;
|
|
71
|
-
/**
|
|
72
|
-
* Refresh sessions list
|
|
73
|
-
*/
|
|
74
|
-
refreshSessions(): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Get current sessions
|
|
77
|
-
*/
|
|
78
|
-
getSessions(): any[];
|
|
79
|
-
/**
|
|
80
|
-
* Switch to a different session
|
|
81
|
-
*/
|
|
82
|
-
switchSession(sessionId: string): Promise<void>;
|
|
83
|
-
/**
|
|
84
|
-
* Remove a session (alias for logout with sessionId)
|
|
85
|
-
*/
|
|
86
|
-
removeSession(sessionId: string): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Logout all sessions
|
|
89
|
-
*/
|
|
90
|
-
logoutAll(): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Clear authentication state
|
|
93
|
-
*/
|
|
94
|
-
private clearAuthState;
|
|
95
|
-
/**
|
|
96
|
-
* Update state and notify listeners
|
|
97
|
-
*/
|
|
98
|
-
private updateState;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=AuthManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthManager.d.ts","sourceRoot":"","sources":["../../../src/core/AuthManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,WA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