@oxyhq/services 5.7.4 → 5.7.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.
- package/README.md +121 -264
- package/lib/commonjs/core/auth-manager.js +440 -0
- package/lib/commonjs/core/auth-manager.js.map +1 -0
- package/lib/commonjs/core/index.js +102 -5
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/use-auth.js +244 -0
- package/lib/commonjs/core/use-auth.js.map +1 -0
- package/lib/commonjs/node/index.js +2 -49
- package/lib/commonjs/node/index.js.map +1 -1
- package/lib/commonjs/ui/index.js +1 -16
- package/lib/commonjs/ui/index.js.map +1 -1
- package/lib/module/core/auth-manager.js +432 -0
- package/lib/module/core/auth-manager.js.map +1 -0
- package/lib/module/core/index.js +41 -5
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/use-auth.js +235 -0
- package/lib/module/core/use-auth.js.map +1 -0
- package/lib/module/node/index.js +1 -11
- package/lib/module/node/index.js.map +1 -1
- package/lib/module/ui/index.js +1 -16
- package/lib/module/ui/index.js.map +1 -1
- package/lib/typescript/core/auth-manager.d.ts +136 -0
- package/lib/typescript/core/auth-manager.d.ts.map +1 -0
- package/lib/typescript/core/index.d.ts +24 -1
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/core/use-auth.d.ts +79 -0
- package/lib/typescript/core/use-auth.d.ts.map +1 -0
- package/lib/typescript/node/index.d.ts +1 -7
- package/lib/typescript/node/index.d.ts.map +1 -1
- package/lib/typescript/ui/index.d.ts +1 -2
- package/lib/typescript/ui/index.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/__tests__/zero-config-auth.test.ts +607 -0
- package/src/core/auth-manager.ts +500 -0
- package/src/core/index.ts +41 -6
- package/src/core/use-auth.tsx +245 -0
- package/src/node/index.ts +1 -17
- package/src/ui/index.ts +1 -19
- package/lib/commonjs/node/middleware.js +0 -227
- package/lib/commonjs/node/middleware.js.map +0 -1
- package/lib/commonjs/ui/zero-config/index.js +0 -25
- package/lib/commonjs/ui/zero-config/index.js.map +0 -1
- package/lib/commonjs/ui/zero-config/provider.js +0 -278
- package/lib/commonjs/ui/zero-config/provider.js.map +0 -1
- package/lib/module/node/middleware.js +0 -199
- package/lib/module/node/middleware.js.map +0 -1
- package/lib/module/ui/zero-config/index.js +0 -8
- package/lib/module/ui/zero-config/index.js.map +0 -1
- package/lib/module/ui/zero-config/provider.js +0 -270
- package/lib/module/ui/zero-config/provider.js.map +0 -1
- package/lib/typescript/node/middleware.d.ts +0 -92
- package/lib/typescript/node/middleware.d.ts.map +0 -1
- package/lib/typescript/ui/zero-config/index.d.ts +0 -5
- package/lib/typescript/ui/zero-config/index.d.ts.map +0 -1
- package/lib/typescript/ui/zero-config/provider.d.ts +0 -84
- package/lib/typescript/ui/zero-config/provider.d.ts.map +0 -1
- package/src/node/middleware.ts +0 -234
- package/src/ui/zero-config/index.ts +0 -11
- package/src/ui/zero-config/provider.tsx +0 -310
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zero-Config Authentication Manager
|
|
5
|
+
*
|
|
6
|
+
* This module provides automatic token management, session handling,
|
|
7
|
+
* and seamless authentication for Oxy services.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
import { jwtDecode } from 'jwt-decode';
|
|
12
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
13
|
+
export class AuthenticationManager {
|
|
14
|
+
tokens = null;
|
|
15
|
+
user = null;
|
|
16
|
+
refreshPromise = null;
|
|
17
|
+
listeners = [];
|
|
18
|
+
storageKey = '@oxy/auth-tokens';
|
|
19
|
+
constructor(baseURL) {
|
|
20
|
+
this.client = axios.create({
|
|
21
|
+
baseURL,
|
|
22
|
+
timeout: 15000,
|
|
23
|
+
withCredentials: true // Enable cookies for session management
|
|
24
|
+
});
|
|
25
|
+
this.setupInterceptors();
|
|
26
|
+
this.initializeFromStorage();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Setup axios interceptors for automatic token management
|
|
31
|
+
*/
|
|
32
|
+
setupInterceptors() {
|
|
33
|
+
// Request interceptor - automatically add auth headers
|
|
34
|
+
this.client.interceptors.request.use(async config => {
|
|
35
|
+
// Skip auth for login/signup endpoints
|
|
36
|
+
if (this.isPublicEndpoint(config.url || '')) {
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Ensure we have a valid token
|
|
41
|
+
await this.ensureValidToken();
|
|
42
|
+
|
|
43
|
+
// Add authorization header if we have a token
|
|
44
|
+
if (this.tokens?.accessToken) {
|
|
45
|
+
config.headers = config.headers || {};
|
|
46
|
+
config.headers.Authorization = `Bearer ${this.tokens.accessToken}`;
|
|
47
|
+
}
|
|
48
|
+
return config;
|
|
49
|
+
}, error => Promise.reject(error));
|
|
50
|
+
|
|
51
|
+
// Response interceptor - handle token expiration and auto-retry
|
|
52
|
+
this.client.interceptors.response.use(response => response, async error => {
|
|
53
|
+
const originalRequest = error.config;
|
|
54
|
+
|
|
55
|
+
// If it's a 401 and we haven't already retried, attempt token refresh
|
|
56
|
+
if (error.response?.status === 401 && !originalRequest._retry && this.tokens?.refreshToken && !this.isPublicEndpoint(originalRequest?.url || '')) {
|
|
57
|
+
originalRequest._retry = true;
|
|
58
|
+
try {
|
|
59
|
+
await this.refreshTokens();
|
|
60
|
+
|
|
61
|
+
// Retry original request with new token
|
|
62
|
+
if (originalRequest && this.tokens?.accessToken) {
|
|
63
|
+
originalRequest.headers = originalRequest.headers || {};
|
|
64
|
+
originalRequest.headers.Authorization = `Bearer ${this.tokens.accessToken}`;
|
|
65
|
+
return this.client(originalRequest);
|
|
66
|
+
}
|
|
67
|
+
} catch (refreshError) {
|
|
68
|
+
// Refresh failed, clear tokens and notify listeners
|
|
69
|
+
await this.logout();
|
|
70
|
+
return Promise.reject(error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// For non-auth errors or failed retries, reject with formatted error
|
|
75
|
+
return Promise.reject(this.formatError(error));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Check if endpoint is public (doesn't require authentication)
|
|
81
|
+
*/
|
|
82
|
+
isPublicEndpoint(url) {
|
|
83
|
+
const publicPaths = ['/auth/login', '/auth/signup', '/auth/register', '/auth/check-username', '/auth/check-email', '/health', '/'];
|
|
84
|
+
return publicPaths.some(path => url.includes(path));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Initialize authentication state from persistent storage
|
|
89
|
+
*/
|
|
90
|
+
async initializeFromStorage() {
|
|
91
|
+
try {
|
|
92
|
+
const storedData = await AsyncStorage.getItem(this.storageKey);
|
|
93
|
+
if (storedData) {
|
|
94
|
+
const tokens = JSON.parse(storedData);
|
|
95
|
+
|
|
96
|
+
// Validate that tokens haven't expired
|
|
97
|
+
if (await this.validateStoredTokens(tokens)) {
|
|
98
|
+
this.tokens = tokens;
|
|
99
|
+
await this.fetchCurrentUser();
|
|
100
|
+
this.notifyStateChange();
|
|
101
|
+
} else {
|
|
102
|
+
// Tokens expired, clear storage
|
|
103
|
+
await AsyncStorage.removeItem(this.storageKey);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.warn('[OxyAuth] Failed to initialize from storage:', error);
|
|
108
|
+
await AsyncStorage.removeItem(this.storageKey);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Validate stored tokens without making network calls if possible
|
|
114
|
+
*/
|
|
115
|
+
async validateStoredTokens(tokens) {
|
|
116
|
+
try {
|
|
117
|
+
// First check if access token is expired
|
|
118
|
+
const decoded = jwtDecode(tokens.accessToken);
|
|
119
|
+
const now = Math.floor(Date.now() / 1000);
|
|
120
|
+
|
|
121
|
+
// If access token is still valid, we're good
|
|
122
|
+
if (decoded.exp > now + 60) {
|
|
123
|
+
// 60 second buffer
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Access token expired, try refresh token
|
|
128
|
+
const refreshDecoded = jwtDecode(tokens.refreshToken);
|
|
129
|
+
return refreshDecoded.exp > now;
|
|
130
|
+
} catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Ensure we have a valid access token
|
|
137
|
+
*/
|
|
138
|
+
async ensureValidToken() {
|
|
139
|
+
if (!this.tokens?.accessToken) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const decoded = jwtDecode(this.tokens.accessToken);
|
|
144
|
+
const now = Math.floor(Date.now() / 1000);
|
|
145
|
+
|
|
146
|
+
// Refresh if token expires within 5 minutes
|
|
147
|
+
if (decoded.exp - now < 300) {
|
|
148
|
+
await this.refreshTokens();
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.warn('[OxyAuth] Token validation error:', error);
|
|
152
|
+
// If token is malformed, try refresh
|
|
153
|
+
if (this.tokens?.refreshToken) {
|
|
154
|
+
await this.refreshTokens();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Login with credentials
|
|
161
|
+
*/
|
|
162
|
+
async login(credentials) {
|
|
163
|
+
try {
|
|
164
|
+
const response = await this.client.post('/auth/login', credentials);
|
|
165
|
+
const loginData = response.data;
|
|
166
|
+
if (loginData.success && loginData.accessToken && loginData.refreshToken) {
|
|
167
|
+
await this.setTokens({
|
|
168
|
+
accessToken: loginData.accessToken,
|
|
169
|
+
refreshToken: loginData.refreshToken
|
|
170
|
+
});
|
|
171
|
+
this.user = loginData.user;
|
|
172
|
+
this.notifyStateChange();
|
|
173
|
+
return loginData;
|
|
174
|
+
} else {
|
|
175
|
+
throw new Error(loginData.message || 'Login failed');
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw this.formatError(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Register new user
|
|
184
|
+
*/
|
|
185
|
+
async register(userData) {
|
|
186
|
+
try {
|
|
187
|
+
const response = await this.client.post('/auth/register', userData);
|
|
188
|
+
const registerData = response.data;
|
|
189
|
+
if (registerData.success && registerData.accessToken && registerData.refreshToken) {
|
|
190
|
+
await this.setTokens({
|
|
191
|
+
accessToken: registerData.accessToken,
|
|
192
|
+
refreshToken: registerData.refreshToken
|
|
193
|
+
});
|
|
194
|
+
this.user = registerData.user;
|
|
195
|
+
this.notifyStateChange();
|
|
196
|
+
return registerData;
|
|
197
|
+
} else {
|
|
198
|
+
throw new Error(registerData.message || 'Registration failed');
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
throw this.formatError(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Logout user and clear all tokens
|
|
207
|
+
*/
|
|
208
|
+
async logout() {
|
|
209
|
+
// Attempt server-side logout if we have tokens
|
|
210
|
+
if (this.tokens?.refreshToken) {
|
|
211
|
+
try {
|
|
212
|
+
await this.client.post('/auth/logout', {
|
|
213
|
+
refreshToken: this.tokens.refreshToken
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.warn('[OxyAuth] Server logout failed:', error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Clear local state
|
|
221
|
+
this.tokens = null;
|
|
222
|
+
this.user = null;
|
|
223
|
+
|
|
224
|
+
// Clear storage
|
|
225
|
+
try {
|
|
226
|
+
await AsyncStorage.removeItem(this.storageKey);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.warn('[OxyAuth] Failed to clear storage:', error);
|
|
229
|
+
}
|
|
230
|
+
this.notifyStateChange();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Refresh access token using refresh token
|
|
235
|
+
*/
|
|
236
|
+
async refreshTokens() {
|
|
237
|
+
if (!this.tokens?.refreshToken) {
|
|
238
|
+
throw new Error('No refresh token available');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// If refresh is already in progress, return that promise
|
|
242
|
+
if (this.refreshPromise) {
|
|
243
|
+
return this.refreshPromise;
|
|
244
|
+
}
|
|
245
|
+
this.refreshPromise = this.performTokenRefresh();
|
|
246
|
+
try {
|
|
247
|
+
const newTokens = await this.refreshPromise;
|
|
248
|
+
this.refreshPromise = null;
|
|
249
|
+
return newTokens;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
this.refreshPromise = null;
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Perform the actual token refresh
|
|
258
|
+
*/
|
|
259
|
+
async performTokenRefresh() {
|
|
260
|
+
try {
|
|
261
|
+
const response = await this.client.post('/auth/refresh', {
|
|
262
|
+
refreshToken: this.tokens.refreshToken
|
|
263
|
+
});
|
|
264
|
+
const newTokens = {
|
|
265
|
+
accessToken: response.data.accessToken,
|
|
266
|
+
refreshToken: response.data.refreshToken
|
|
267
|
+
};
|
|
268
|
+
await this.setTokens(newTokens);
|
|
269
|
+
return newTokens;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// Refresh failed, clear all tokens
|
|
272
|
+
await this.logout();
|
|
273
|
+
throw this.formatError(error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Set tokens and persist to storage
|
|
279
|
+
*/
|
|
280
|
+
async setTokens(newTokens) {
|
|
281
|
+
this.tokens = newTokens;
|
|
282
|
+
try {
|
|
283
|
+
await AsyncStorage.setItem(this.storageKey, JSON.stringify(newTokens));
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.warn('[OxyAuth] Failed to persist tokens:', error);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Fetch current user profile
|
|
291
|
+
*/
|
|
292
|
+
async fetchCurrentUser() {
|
|
293
|
+
try {
|
|
294
|
+
const response = await this.client.get('/auth/me');
|
|
295
|
+
this.user = response.data.data || response.data;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.warn('[OxyAuth] Failed to fetch current user:', error);
|
|
298
|
+
// Don't throw here, we can still function without user profile
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Get current authentication state
|
|
304
|
+
*/
|
|
305
|
+
getAuthState() {
|
|
306
|
+
return {
|
|
307
|
+
isAuthenticated: !!this.tokens?.accessToken,
|
|
308
|
+
user: this.user,
|
|
309
|
+
tokens: this.tokens
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get current user (loads if not cached)
|
|
315
|
+
*/
|
|
316
|
+
async getCurrentUser() {
|
|
317
|
+
if (!this.tokens?.accessToken) {
|
|
318
|
+
throw new Error('Not authenticated');
|
|
319
|
+
}
|
|
320
|
+
if (!this.user) {
|
|
321
|
+
await this.fetchCurrentUser();
|
|
322
|
+
}
|
|
323
|
+
return this.user;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Subscribe to authentication state changes
|
|
328
|
+
*/
|
|
329
|
+
onAuthStateChange(callback) {
|
|
330
|
+
this.listeners.push(callback);
|
|
331
|
+
|
|
332
|
+
// Immediately call with current state
|
|
333
|
+
callback(this.getAuthState());
|
|
334
|
+
|
|
335
|
+
// Return unsubscribe function
|
|
336
|
+
return () => {
|
|
337
|
+
this.listeners = this.listeners.filter(listener => listener !== callback);
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Notify all listeners of state changes
|
|
343
|
+
*/
|
|
344
|
+
notifyStateChange() {
|
|
345
|
+
const state = this.getAuthState();
|
|
346
|
+
this.listeners.forEach(listener => {
|
|
347
|
+
try {
|
|
348
|
+
listener(state);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error('[OxyAuth] Listener error:', error);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Format error responses consistently
|
|
357
|
+
*/
|
|
358
|
+
formatError(error) {
|
|
359
|
+
if (error?.response?.data?.message) {
|
|
360
|
+
return new Error(error.response.data.message);
|
|
361
|
+
}
|
|
362
|
+
if (error?.message) {
|
|
363
|
+
return new Error(error.message);
|
|
364
|
+
}
|
|
365
|
+
return new Error('An unexpected error occurred');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Get authenticated HTTP client for making API calls
|
|
370
|
+
*/
|
|
371
|
+
getClient() {
|
|
372
|
+
return this.client;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Check username availability
|
|
377
|
+
*/
|
|
378
|
+
async checkUsernameAvailability(username) {
|
|
379
|
+
try {
|
|
380
|
+
const response = await this.client.get(`/auth/check-username/${encodeURIComponent(username)}`);
|
|
381
|
+
return response.data;
|
|
382
|
+
} catch (error) {
|
|
383
|
+
const axiosError = error;
|
|
384
|
+
if (axiosError?.response?.status === 400) {
|
|
385
|
+
return axiosError.response.data;
|
|
386
|
+
}
|
|
387
|
+
throw this.formatError(error);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Check email availability
|
|
393
|
+
*/
|
|
394
|
+
async checkEmailAvailability(email) {
|
|
395
|
+
try {
|
|
396
|
+
const response = await this.client.post('/auth/check-email', {
|
|
397
|
+
email
|
|
398
|
+
});
|
|
399
|
+
return response.data;
|
|
400
|
+
} catch (error) {
|
|
401
|
+
const axiosError = error;
|
|
402
|
+
if (axiosError?.response?.status === 400) {
|
|
403
|
+
return axiosError.response.data;
|
|
404
|
+
}
|
|
405
|
+
throw this.formatError(error);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Global auth manager instance
|
|
411
|
+
let globalAuthManager = null;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Initialize global authentication manager
|
|
415
|
+
*/
|
|
416
|
+
export function initializeAuth(baseURL) {
|
|
417
|
+
if (!globalAuthManager) {
|
|
418
|
+
globalAuthManager = new AuthenticationManager(baseURL);
|
|
419
|
+
}
|
|
420
|
+
return globalAuthManager;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Get global authentication manager instance
|
|
425
|
+
*/
|
|
426
|
+
export function getAuthManager() {
|
|
427
|
+
if (!globalAuthManager) {
|
|
428
|
+
throw new Error('Authentication manager not initialized. Call initializeAuth() first.');
|
|
429
|
+
}
|
|
430
|
+
return globalAuthManager;
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=auth-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["axios","jwtDecode","AsyncStorage","AuthenticationManager","tokens","user","refreshPromise","listeners","storageKey","constructor","baseURL","client","create","timeout","withCredentials","setupInterceptors","initializeFromStorage","interceptors","request","use","config","isPublicEndpoint","url","ensureValidToken","accessToken","headers","Authorization","error","Promise","reject","response","originalRequest","status","_retry","refreshToken","refreshTokens","refreshError","logout","formatError","publicPaths","some","path","includes","storedData","getItem","JSON","parse","validateStoredTokens","fetchCurrentUser","notifyStateChange","removeItem","console","warn","decoded","now","Math","floor","Date","exp","refreshDecoded","login","credentials","post","loginData","data","success","setTokens","Error","message","register","userData","registerData","performTokenRefresh","newTokens","setItem","stringify","get","getAuthState","isAuthenticated","getCurrentUser","onAuthStateChange","callback","push","filter","listener","state","forEach","getClient","checkUsernameAvailability","username","encodeURIComponent","axiosError","checkEmailAvailability","email","globalAuthManager","initializeAuth","getAuthManager"],"sourceRoot":"../../../src","sources":["core/auth-manager.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAiE,OAAO;AACpF,SAASC,SAAS,QAAQ,YAAY;AACtC,OAAOC,YAAY,MAAM,2CAA2C;AAiCpE,OAAO,MAAMC,qBAAqB,CAAC;EAEzBC,MAAM,GAAsB,IAAI;EAChCC,IAAI,GAAe,IAAI;EACvBC,cAAc,GAA+B,IAAI;EACjDC,SAAS,GAAmC,EAAE;EAC9CC,UAAU,GAAG,kBAAkB;EAEvCC,WAAWA,CAACC,OAAe,EAAE;IAC3B,IAAI,CAACC,MAAM,GAAGX,KAAK,CAACY,MAAM,CAAC;MACzBF,OAAO;MACPG,OAAO,EAAE,KAAK;MACdC,eAAe,EAAE,IAAI,CAAE;IACzB,CAAC,CAAC;IAEF,IAAI,CAACC,iBAAiB,CAAC,CAAC;IACxB,IAAI,CAACC,qBAAqB,CAAC,CAAC;EAC9B;;EAEA;AACF;AACA;EACUD,iBAAiBA,CAAA,EAAS;IAChC;IACA,IAAI,CAACJ,MAAM,CAACM,YAAY,CAACC,OAAO,CAACC,GAAG,CAClC,MAAOC,MAAkC,IAAK;MAC5C;MACA,IAAI,IAAI,CAACC,gBAAgB,CAACD,MAAM,CAACE,GAAG,IAAI,EAAE,CAAC,EAAE;QAC3C,OAAOF,MAAM;MACf;;MAEA;MACA,MAAM,IAAI,CAACG,gBAAgB,CAAC,CAAC;;MAE7B;MACA,IAAI,IAAI,CAACnB,MAAM,EAAEoB,WAAW,EAAE;QAC5BJ,MAAM,CAACK,OAAO,GAAGL,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;QACrCL,MAAM,CAACK,OAAO,CAACC,aAAa,GAAG,UAAU,IAAI,CAACtB,MAAM,CAACoB,WAAW,EAAE;MACpE;MAEA,OAAOJ,MAAM;IACf,CAAC,EACAO,KAAK,IAAKC,OAAO,CAACC,MAA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ACrE,IAAI,CAACoF,iBAAiB,EAAE;IACtBA,iBAAiB,GAAG,IAAI3F,qBAAqB,CAACO,OAAO,CAAC;EACxD;EACA,OAAOoF,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA,OAAO,SAASE,cAAcA,CAAA,EAA0B;EACtD,IAAI,CAACF,iBAAiB,EAAE;IACtB,MAAM,IAAI3B,KAAK,CAAC,sEAAsE,CAAC;EACzF;EACA,OAAO2B,iBAAiB;AAC1B","ignoreList":[]}
|
package/lib/module/core/index.js
CHANGED
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import { jwtDecode } from 'jwt-decode';
|
|
5
5
|
|
|
6
|
+
// Zero-Config Authentication Exports
|
|
7
|
+
export { AuthenticationManager, initializeAuth, getAuthManager } from './auth-manager';
|
|
8
|
+
export { AuthProvider, useAuth, useOxyClient, useAuthStatus, useCurrentUser, withAuth } from './use-auth';
|
|
9
|
+
|
|
6
10
|
// Remove all FormData, form-data, and polyfill logic. Delete uploadFile and uploadFiles methods. Add a comment to use the new raw upload approach instead.
|
|
7
11
|
|
|
8
12
|
// Import secure session types
|
|
9
13
|
|
|
14
|
+
import { initializeAuth } from './auth-manager';
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* Default cloud URL for Oxy services, cloud is where the user files are. (e.g. images, videos, etc.). Not the API.
|
|
12
18
|
*/
|
|
@@ -17,24 +23,54 @@ export { DeviceManager } from '../utils/deviceManager';
|
|
|
17
23
|
/**
|
|
18
24
|
* OxyServices - Client library for interacting with the Oxy API
|
|
19
25
|
*
|
|
20
|
-
*
|
|
26
|
+
* ZERO-CONFIG MODE:
|
|
27
|
+
* Use the new AuthProvider and useAuth hooks for automatic authentication management:
|
|
28
|
+
*
|
|
29
|
+
* import { AuthProvider, useAuth } from '@oxyhq/services';
|
|
30
|
+
*
|
|
31
|
+
* <AuthProvider baseURL="https://api.oxy.so">
|
|
32
|
+
* <App />
|
|
33
|
+
* </AuthProvider>
|
|
34
|
+
*
|
|
35
|
+
* Then in components:
|
|
36
|
+
* const { login, user, isAuthenticated } = useAuth();
|
|
37
|
+
*
|
|
38
|
+
* LEGACY MODE:
|
|
39
|
+
* The OxyServices class below is maintained for backward compatibility
|
|
40
|
+
* but we recommend migrating to the new zero-config approach.
|
|
41
|
+
*
|
|
42
|
+
* Note: For authentication status in UI components, use `isAuthenticated` from useAuth() context
|
|
21
43
|
* instead of checking token status directly on this service.
|
|
22
44
|
*/
|
|
23
45
|
export class OxyServices {
|
|
24
46
|
accessToken = null;
|
|
25
47
|
refreshToken = null;
|
|
26
48
|
refreshPromise = null;
|
|
49
|
+
authManager = null;
|
|
27
50
|
|
|
28
51
|
/**
|
|
29
52
|
* Creates a new instance of the OxyServices client
|
|
30
53
|
* @param config - Configuration for the client
|
|
31
54
|
*/
|
|
32
55
|
constructor(config) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
// Try to use the new auth manager if available, otherwise fall back to legacy mode
|
|
57
|
+
try {
|
|
58
|
+
this.authManager = initializeAuth(config.baseURL);
|
|
59
|
+
this.client = this.authManager.getClient();
|
|
60
|
+
} catch {
|
|
61
|
+
// Fall back to legacy implementation
|
|
62
|
+
this.client = axios.create({
|
|
63
|
+
baseURL: config.baseURL,
|
|
64
|
+
timeout: 10000 // 10 second timeout
|
|
65
|
+
});
|
|
66
|
+
this.setupLegacyInterceptors();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
37
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Setup legacy interceptors (only used if auth manager is not available)
|
|
72
|
+
*/
|
|
73
|
+
setupLegacyInterceptors() {
|
|
38
74
|
// Interceptor for adding auth header and handling token refresh
|
|
39
75
|
this.client.interceptors.request.use(async req => {
|
|
40
76
|
if (!this.accessToken) {
|