@oxyhq/services 5.7.5 → 5.8.1
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 +76 -76
- package/lib/commonjs/core/index.js +177 -102
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/index.js +88 -29
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/node/createAuth.js +585 -7
- package/lib/commonjs/node/createAuth.js.map +1 -1
- package/lib/commonjs/node/index.js +38 -1
- package/lib/commonjs/node/index.js.map +1 -1
- package/lib/commonjs/ui/components/Avatar.js +15 -6
- package/lib/commonjs/ui/components/Avatar.js.map +1 -1
- package/lib/commonjs/ui/components/GroupedItem.js +58 -13
- package/lib/commonjs/ui/components/GroupedItem.js.map +1 -1
- package/lib/commonjs/ui/components/GroupedSection.js +7 -1
- package/lib/commonjs/ui/components/GroupedSection.js.map +1 -1
- package/lib/commonjs/ui/components/Header.js +322 -0
- package/lib/commonjs/ui/components/Header.js.map +1 -0
- package/lib/commonjs/ui/components/OxyProvider.js +23 -7
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/components/index.js +7 -0
- package/lib/commonjs/ui/components/index.js.map +1 -1
- package/lib/commonjs/ui/components/internal/GroupedPillButtons.js +1 -1
- package/lib/commonjs/ui/components/internal/GroupedPillButtons.js.map +1 -1
- package/lib/commonjs/ui/components/internal/TextField.js +606 -546
- package/lib/commonjs/ui/components/internal/TextField.js.map +1 -1
- package/lib/commonjs/ui/components/internal/TextField.md +436 -0
- package/lib/commonjs/ui/context/OxyContext.js +122 -78
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useSessionSocket.js +5 -2
- package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/commonjs/ui/navigation/OxyRouter.js +1 -1
- package/lib/commonjs/ui/navigation/OxyRouter.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +6 -6
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountManagementDemo.js +3 -3
- package/lib/commonjs/ui/screens/AccountManagementDemo.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js +241 -598
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +1151 -406
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +135 -237
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AppInfoScreen.js +246 -463
- package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FeedbackScreen.js +3 -3
- package/lib/commonjs/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js +808 -650
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/RecoverAccountScreen.js +51 -72
- package/lib/commonjs/ui/screens/RecoverAccountScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SessionManagementScreen.js +11 -29
- package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SignInScreen.js +30 -303
- package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SignUpScreen.js +4 -4
- package/lib/commonjs/ui/screens/SignUpScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js +19 -31
- package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js.map +1 -1
- package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js +7 -10
- package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js.map +1 -1
- package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js +11 -5
- package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js.map +1 -1
- package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js +11 -4
- package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js.map +1 -1
- package/lib/commonjs/ui/stores/authStore.js +12 -0
- package/lib/commonjs/ui/stores/authStore.js.map +1 -1
- package/lib/commonjs/ui/styles/authStyles.js +337 -0
- package/lib/commonjs/ui/styles/authStyles.js.map +1 -0
- package/lib/commonjs/ui/styles/index.js +11 -0
- package/lib/commonjs/ui/styles/index.js.map +1 -1
- package/lib/module/core/index.js +177 -41
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/index.js +26 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/node/createAuth.js +584 -7
- package/lib/module/node/createAuth.js.map +1 -1
- package/lib/module/node/index.js +7 -1
- package/lib/module/node/index.js.map +1 -1
- package/lib/module/ui/components/Avatar.js +15 -6
- package/lib/module/ui/components/Avatar.js.map +1 -1
- package/lib/module/ui/components/GroupedItem.js +59 -14
- package/lib/module/ui/components/GroupedItem.js.map +1 -1
- package/lib/module/ui/components/GroupedSection.js +7 -1
- package/lib/module/ui/components/GroupedSection.js.map +1 -1
- package/lib/module/ui/components/Header.js +317 -0
- package/lib/module/ui/components/Header.js.map +1 -0
- package/lib/module/ui/components/OxyProvider.js +25 -9
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/components/index.js +1 -0
- package/lib/module/ui/components/index.js.map +1 -1
- package/lib/module/ui/components/internal/GroupedPillButtons.js +1 -1
- package/lib/module/ui/components/internal/GroupedPillButtons.js.map +1 -1
- package/lib/module/ui/components/internal/TextField.js +607 -547
- package/lib/module/ui/components/internal/TextField.js.map +1 -1
- package/lib/module/ui/components/internal/TextField.md +436 -0
- package/lib/module/ui/context/OxyContext.js +121 -77
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/hooks/useSessionSocket.js +5 -2
- package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/module/ui/navigation/OxyRouter.js +1 -1
- package/lib/module/ui/navigation/OxyRouter.js.map +1 -1
- package/lib/module/ui/screens/AccountCenterScreen.js +6 -6
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountManagementDemo.js +3 -3
- package/lib/module/ui/screens/AccountManagementDemo.js.map +1 -1
- package/lib/module/ui/screens/AccountOverviewScreen.js +242 -597
- package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +1152 -407
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +135 -237
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/AppInfoScreen.js +248 -465
- package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/module/ui/screens/FeedbackScreen.js +3 -3
- package/lib/module/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/module/ui/screens/PaymentGatewayScreen.js +809 -651
- package/lib/module/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/module/ui/screens/RecoverAccountScreen.js +53 -74
- package/lib/module/ui/screens/RecoverAccountScreen.js.map +1 -1
- package/lib/module/ui/screens/SessionManagementScreen.js +11 -29
- package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/SignInScreen.js +32 -305
- package/lib/module/ui/screens/SignInScreen.js.map +1 -1
- package/lib/module/ui/screens/SignUpScreen.js +5 -5
- package/lib/module/ui/screens/SignUpScreen.js.map +1 -1
- package/lib/module/ui/screens/internal/SignInPasswordStep.js +19 -31
- package/lib/module/ui/screens/internal/SignInPasswordStep.js.map +1 -1
- package/lib/module/ui/screens/internal/SignInUsernameStep.js +7 -10
- package/lib/module/ui/screens/internal/SignInUsernameStep.js.map +1 -1
- package/lib/module/ui/screens/internal/SignUpIdentityStep.js +11 -5
- package/lib/module/ui/screens/internal/SignUpIdentityStep.js.map +1 -1
- package/lib/module/ui/screens/internal/SignUpSecurityStep.js +11 -4
- package/lib/module/ui/screens/internal/SignUpSecurityStep.js.map +1 -1
- package/lib/module/ui/stores/authStore.js +12 -0
- package/lib/module/ui/stores/authStore.js.map +1 -1
- package/lib/module/ui/styles/authStyles.js +332 -0
- package/lib/module/ui/styles/authStyles.js.map +1 -0
- package/lib/module/ui/styles/index.js +1 -0
- package/lib/module/ui/styles/index.js.map +1 -1
- package/lib/typescript/core/index.d.ts +68 -24
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +13 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/node/createAuth.d.ts +112 -0
- package/lib/typescript/node/createAuth.d.ts.map +1 -1
- package/lib/typescript/node/index.d.ts +2 -0
- package/lib/typescript/node/index.d.ts.map +1 -1
- package/lib/typescript/ui/components/Avatar.d.ts.map +1 -1
- package/lib/typescript/ui/components/GroupedItem.d.ts +6 -0
- package/lib/typescript/ui/components/GroupedItem.d.ts.map +1 -1
- package/lib/typescript/ui/components/GroupedSection.d.ts +6 -0
- package/lib/typescript/ui/components/GroupedSection.d.ts.map +1 -1
- package/lib/typescript/ui/components/Header.d.ts +22 -0
- package/lib/typescript/ui/components/Header.d.ts.map +1 -0
- package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/ui/components/index.d.ts +1 -0
- package/lib/typescript/ui/components/index.d.ts.map +1 -1
- package/lib/typescript/ui/components/internal/TextField.d.ts +31 -16
- package/lib/typescript/ui/components/internal/TextField.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +5 -2
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useSessionSocket.d.ts.map +1 -1
- package/lib/typescript/ui/navigation/types.d.ts +9 -2
- package/lib/typescript/ui/navigation/types.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AppInfoScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PaymentGatewayScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/RecoverAccountScreen.d.ts +5 -1
- package/lib/typescript/ui/screens/RecoverAccountScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SessionManagementScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SignInScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts +1 -1
- package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts.map +1 -1
- package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts +0 -1
- package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts.map +1 -1
- package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts.map +1 -1
- package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts.map +1 -1
- package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
- package/lib/typescript/ui/styles/authStyles.d.ts +326 -0
- package/lib/typescript/ui/styles/authStyles.d.ts.map +1 -0
- package/lib/typescript/ui/styles/index.d.ts +1 -0
- package/lib/typescript/ui/styles/index.d.ts.map +1 -1
- package/package.json +1 -4
- package/src/core/index.ts +195 -41
- package/src/index.ts +72 -4
- package/src/node/createAuth.ts +623 -7
- package/src/node/index.ts +19 -1
- package/src/ui/components/Avatar.tsx +11 -5
- package/src/ui/components/GroupedItem.tsx +57 -9
- package/src/ui/components/GroupedSection.tsx +12 -0
- package/src/ui/components/Header.tsx +364 -0
- package/src/ui/components/OxyProvider.tsx +31 -15
- package/src/ui/components/index.ts +1 -0
- package/src/ui/components/internal/GroupedPillButtons.tsx +1 -1
- package/src/ui/components/internal/TextField.md +436 -0
- package/src/ui/components/internal/TextField.tsx +720 -620
- package/src/ui/context/OxyContext.tsx +150 -63
- package/src/ui/hooks/useSessionSocket.ts +5 -2
- package/src/ui/navigation/OxyRouter.tsx +1 -1
- package/src/ui/navigation/types.ts +10 -2
- package/src/ui/screens/AccountCenterScreen.tsx +5 -5
- package/src/ui/screens/AccountManagementDemo.tsx +9 -9
- package/src/ui/screens/AccountOverviewScreen.tsx +265 -414
- package/src/ui/screens/AccountSettingsScreen.tsx +1165 -403
- package/src/ui/screens/AccountSwitcherScreen.tsx +158 -202
- package/src/ui/screens/AppInfoScreen.tsx +270 -497
- package/src/ui/screens/FeedbackScreen.tsx +3 -3
- package/src/ui/screens/PaymentGatewayScreen.tsx +668 -365
- package/src/ui/screens/ProfileScreen.tsx +5 -5
- package/src/ui/screens/RecoverAccountScreen.tsx +46 -74
- package/src/ui/screens/SessionManagementScreen.tsx +14 -22
- package/src/ui/screens/SignInScreen.tsx +27 -294
- package/src/ui/screens/SignUpScreen.tsx +5 -5
- package/src/ui/screens/internal/SignInPasswordStep.tsx +11 -22
- package/src/ui/screens/internal/SignInUsernameStep.tsx +3 -10
- package/src/ui/screens/internal/SignUpIdentityStep.tsx +2 -5
- package/src/ui/screens/internal/SignUpSecurityStep.tsx +3 -4
- package/src/ui/stores/authStore.ts +12 -0
- package/src/ui/styles/authStyles.ts +352 -0
- package/src/ui/styles/index.ts +1 -0
- package/lib/commonjs/core/auth-manager.js +0 -440
- package/lib/commonjs/core/auth-manager.js.map +0 -1
- package/lib/commonjs/core/use-auth.js +0 -244
- package/lib/commonjs/core/use-auth.js.map +0 -1
- package/lib/module/core/auth-manager.js +0 -432
- package/lib/module/core/auth-manager.js.map +0 -1
- package/lib/module/core/use-auth.js +0 -235
- package/lib/module/core/use-auth.js.map +0 -1
- package/lib/typescript/core/auth-manager.d.ts +0 -136
- package/lib/typescript/core/auth-manager.d.ts.map +0 -1
- package/lib/typescript/core/use-auth.d.ts +0 -79
- package/lib/typescript/core/use-auth.d.ts.map +0 -1
- package/src/__tests__/middleware.test.ts +0 -105
- package/src/__tests__/setup.ts +0 -10
- package/src/__tests__/zero-config-auth.test.ts +0 -607
- package/src/core/auth-manager.ts +0 -500
- package/src/core/use-auth.tsx +0 -245
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_authManager","_jsxRuntime","AuthContext","createContext","AuthProvider","children","baseURL","state","setState","useState","isAuthenticated","isLoading","user","error","authManager","initializeAuth","useEffect","unsubscribe","onAuthStateChange","authState","prevState","login","useCallback","username","password","prev","Error","message","register","email","logout","console","getCurrentUser","checkUsernameAvailability","checkEmailAvailability","clearError","contextValue","jsx","Provider","value","useAuth","context","useContext","withAuth","Component","options","redirectTo","LoadingComponent","requireAuth","AuthenticatedComponent","props","useOxyClient","getAuthManager","getClient","useAuthStatus","useCurrentUser","refetch"],"sourceRoot":"../../../src","sources":["core/use-auth.tsx"],"mappings":";;;;;;;;;;;AAMA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAuF,IAAAE,WAAA,GAAAF,OAAA;AAPvF;AACA;AACA;AACA;AACA;;AAsBA,MAAMG,WAAW,gBAAG,IAAAC,oBAAa,EAA0B,IAAI,CAAC;AAOhE;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAAC;EAAEC,QAAQ;EAAEC,OAAO,GAAG;AAAwC,CAAC,EAAE;EAC5F,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAY;IAC5CC,eAAe,EAAE,KAAK;IACtBC,SAAS,EAAE,IAAI;IACfC,IAAI,EAAE,IAAI;IACVC,KAAK,EAAE;EACT,CAAC,CAAC;EAEF,MAAMC,WAAW,GAAG,IAAAC,2BAAc,EAACT,OAAO,CAAC;;EAE3C;EACA,IAAAU,gBAAS,EAAC,MAAM;IACd,MAAMC,WAAW,GAAGH,WAAW,CAACI,iBAAiB,CAAEC,SAAS,IAAK;MAC/DX,QAAQ,CAACY,SAAS,KAAK;QACrB,GAAGA,SAAS;QACZV,eAAe,EA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AA,CAAAoC,GAAA,EAACU,gBAAgB,IAAE,CAAC;IAC7B;IAEA,IAAIC,WAAW,IAAI,CAACtC,eAAe,EAAE;MACnC,IAAIoC,UAAU,EAAE;QACdA,UAAU,CAAC,CAAC;QACZ,OAAO,IAAI;MACb;;MAEA;MACA,OAAO,IAAI;IACb;IAEA,IAAI,CAACE,WAAW,IAAItC,eAAe,EAAE;MACnC;MACA,OAAO,IAAI;IACb;IAEA,oBAAO,IAAAT,WAAA,CAAAoC,GAAA,EAACO,SAAS;MAAA,GAAKM;IAAK,CAAG,CAAC;EACjC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAAA,EAAG;EAC7B,MAAMrC,WAAW,GAAG,IAAAsC,2BAAc,EAAC,CAAC;EACpC,OAAOtC,WAAW,CAACuC,SAAS,CAAC,CAAC;AAChC;;AAEA;AACA;AACA;AACO,SAASC,aAAaA,CAAA,EAAqD;EAChF,MAAM;IAAE5C,eAAe;IAAEC;EAAU,CAAC,GAAG6B,OAAO,CAAC,CAAC;EAChD,OAAO;IAAE9B,eAAe;IAAEC;EAAU,CAAC;AACvC;;AAEA;AACA;AACA;AACO,SAAS4C,cAAcA,CAAA,EAA0E;EACtG,MAAM;IAAE3C,IAAI;IAAED,SAAS;IAAEqB;EAAe,CAAC,GAAGQ,OAAO,CAAC,CAAC;EAErD,OAAO;IACL5B,IAAI;IACJD,SAAS;IACT6C,OAAO,EAAExB;EACX,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,432 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,IA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gE,UAAU,GAAGhE,KAAmB;MACtC,IAAIgE,UAAU,EAAE7D,QAAQ,EAAEE,MAAM,KAAK,GAAG,EAAE;QACxC,OAAQ2D,UAAU,CAAC7D,QAAQ,CAASkC,IAAI;MAC1C;MACA,MAAM,IAAI,CAAC1B,WAAW,CAACX,KAAK,CAAC;IAC/B;EACF;AACF;;AAEA;AACA,IAAImE,iBAA+C,GAAG,IAAI;;AAE1D;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACrF,OAAe,EAAyB;EACrE,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":[]}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Zero-Config Authentication Hook for React/React Native
|
|
5
|
-
*
|
|
6
|
-
* Provides automatic authentication state management with minimal setup required.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { useState, useEffect, useCallback, useContext, createContext } from 'react';
|
|
10
|
-
import { getAuthManager, initializeAuth } from './auth-manager';
|
|
11
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
const AuthContext = /*#__PURE__*/createContext(null);
|
|
13
|
-
/**
|
|
14
|
-
* Authentication Provider Component
|
|
15
|
-
*
|
|
16
|
-
* Wrap your app with this provider to enable zero-config authentication.
|
|
17
|
-
* All authentication state will be automatically managed.
|
|
18
|
-
*/
|
|
19
|
-
export function AuthProvider({
|
|
20
|
-
children,
|
|
21
|
-
baseURL = 'https://api.oxy.so'
|
|
22
|
-
}) {
|
|
23
|
-
const [state, setState] = useState({
|
|
24
|
-
isAuthenticated: false,
|
|
25
|
-
isLoading: true,
|
|
26
|
-
user: null,
|
|
27
|
-
error: null
|
|
28
|
-
});
|
|
29
|
-
const authManager = initializeAuth(baseURL);
|
|
30
|
-
|
|
31
|
-
// Update state when auth manager state changes
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const unsubscribe = authManager.onAuthStateChange(authState => {
|
|
34
|
-
setState(prevState => ({
|
|
35
|
-
...prevState,
|
|
36
|
-
isAuthenticated: authState.isAuthenticated,
|
|
37
|
-
user: authState.user,
|
|
38
|
-
isLoading: false
|
|
39
|
-
}));
|
|
40
|
-
});
|
|
41
|
-
return unsubscribe;
|
|
42
|
-
}, [authManager]);
|
|
43
|
-
const login = useCallback(async (username, password) => {
|
|
44
|
-
setState(prev => ({
|
|
45
|
-
...prev,
|
|
46
|
-
isLoading: true,
|
|
47
|
-
error: null
|
|
48
|
-
}));
|
|
49
|
-
try {
|
|
50
|
-
await authManager.login({
|
|
51
|
-
username,
|
|
52
|
-
password
|
|
53
|
-
});
|
|
54
|
-
// State will be updated via the auth state change listener
|
|
55
|
-
} catch (error) {
|
|
56
|
-
setState(prev => ({
|
|
57
|
-
...prev,
|
|
58
|
-
isLoading: false,
|
|
59
|
-
error: error instanceof Error ? error.message : 'Login failed'
|
|
60
|
-
}));
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}, [authManager]);
|
|
64
|
-
const register = useCallback(async (username, email, password) => {
|
|
65
|
-
setState(prev => ({
|
|
66
|
-
...prev,
|
|
67
|
-
isLoading: true,
|
|
68
|
-
error: null
|
|
69
|
-
}));
|
|
70
|
-
try {
|
|
71
|
-
await authManager.register({
|
|
72
|
-
username,
|
|
73
|
-
email,
|
|
74
|
-
password
|
|
75
|
-
});
|
|
76
|
-
// State will be updated via the auth state change listener
|
|
77
|
-
} catch (error) {
|
|
78
|
-
setState(prev => ({
|
|
79
|
-
...prev,
|
|
80
|
-
isLoading: false,
|
|
81
|
-
error: error instanceof Error ? error.message : 'Registration failed'
|
|
82
|
-
}));
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}, [authManager]);
|
|
86
|
-
const logout = useCallback(async () => {
|
|
87
|
-
setState(prev => ({
|
|
88
|
-
...prev,
|
|
89
|
-
isLoading: true,
|
|
90
|
-
error: null
|
|
91
|
-
}));
|
|
92
|
-
try {
|
|
93
|
-
await authManager.logout();
|
|
94
|
-
// State will be updated via the auth state change listener
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error('Logout error:', error);
|
|
97
|
-
setState(prev => ({
|
|
98
|
-
...prev,
|
|
99
|
-
isLoading: false,
|
|
100
|
-
error: error instanceof Error ? error.message : 'Logout failed'
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
}, [authManager]);
|
|
104
|
-
const getCurrentUser = useCallback(async () => {
|
|
105
|
-
try {
|
|
106
|
-
return await authManager.getCurrentUser();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
setState(prev => ({
|
|
109
|
-
...prev,
|
|
110
|
-
error: error instanceof Error ? error.message : 'Failed to get current user'
|
|
111
|
-
}));
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}, [authManager]);
|
|
115
|
-
const checkUsernameAvailability = useCallback(async username => {
|
|
116
|
-
return await authManager.checkUsernameAvailability(username);
|
|
117
|
-
}, [authManager]);
|
|
118
|
-
const checkEmailAvailability = useCallback(async email => {
|
|
119
|
-
return await authManager.checkEmailAvailability(email);
|
|
120
|
-
}, [authManager]);
|
|
121
|
-
const clearError = useCallback(() => {
|
|
122
|
-
setState(prev => ({
|
|
123
|
-
...prev,
|
|
124
|
-
error: null
|
|
125
|
-
}));
|
|
126
|
-
}, []);
|
|
127
|
-
const contextValue = {
|
|
128
|
-
...state,
|
|
129
|
-
login,
|
|
130
|
-
register,
|
|
131
|
-
logout,
|
|
132
|
-
getCurrentUser,
|
|
133
|
-
checkUsernameAvailability,
|
|
134
|
-
checkEmailAvailability,
|
|
135
|
-
clearError
|
|
136
|
-
};
|
|
137
|
-
return /*#__PURE__*/_jsx(AuthContext.Provider, {
|
|
138
|
-
value: contextValue,
|
|
139
|
-
children: children
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Authentication Hook
|
|
145
|
-
*
|
|
146
|
-
* Use this hook in any component to access authentication state and methods.
|
|
147
|
-
* No additional setup required - just wrap your app with AuthProvider.
|
|
148
|
-
*/
|
|
149
|
-
export function useAuth() {
|
|
150
|
-
const context = useContext(AuthContext);
|
|
151
|
-
if (!context) {
|
|
152
|
-
throw new Error('useAuth must be used within an AuthProvider');
|
|
153
|
-
}
|
|
154
|
-
return context;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Higher-Order Component for authentication
|
|
159
|
-
*
|
|
160
|
-
* Wraps a component to ensure user is authenticated before rendering.
|
|
161
|
-
* Automatically redirects to login if not authenticated.
|
|
162
|
-
*/
|
|
163
|
-
export function withAuth(Component, options = {}) {
|
|
164
|
-
const {
|
|
165
|
-
redirectTo,
|
|
166
|
-
LoadingComponent = () => null,
|
|
167
|
-
requireAuth = true
|
|
168
|
-
} = options;
|
|
169
|
-
return function AuthenticatedComponent(props) {
|
|
170
|
-
const {
|
|
171
|
-
isAuthenticated,
|
|
172
|
-
isLoading
|
|
173
|
-
} = useAuth();
|
|
174
|
-
if (isLoading) {
|
|
175
|
-
return /*#__PURE__*/_jsx(LoadingComponent, {});
|
|
176
|
-
}
|
|
177
|
-
if (requireAuth && !isAuthenticated) {
|
|
178
|
-
if (redirectTo) {
|
|
179
|
-
redirectTo();
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Default behavior - render nothing if not authenticated
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
if (!requireAuth && isAuthenticated) {
|
|
187
|
-
// Component should only be shown to non-authenticated users
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
return /*#__PURE__*/_jsx(Component, {
|
|
191
|
-
...props
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Hook for authenticated API calls
|
|
198
|
-
*
|
|
199
|
-
* Returns an authenticated HTTP client that automatically handles tokens.
|
|
200
|
-
*/
|
|
201
|
-
export function useOxyClient() {
|
|
202
|
-
const authManager = getAuthManager();
|
|
203
|
-
return authManager.getClient();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Hook for authentication status only (minimal re-renders)
|
|
208
|
-
*/
|
|
209
|
-
export function useAuthStatus() {
|
|
210
|
-
const {
|
|
211
|
-
isAuthenticated,
|
|
212
|
-
isLoading
|
|
213
|
-
} = useAuth();
|
|
214
|
-
return {
|
|
215
|
-
isAuthenticated,
|
|
216
|
-
isLoading
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Hook for current user data
|
|
222
|
-
*/
|
|
223
|
-
export function useCurrentUser() {
|
|
224
|
-
const {
|
|
225
|
-
user,
|
|
226
|
-
isLoading,
|
|
227
|
-
getCurrentUser
|
|
228
|
-
} = useAuth();
|
|
229
|
-
return {
|
|
230
|
-
user,
|
|
231
|
-
isLoading,
|
|
232
|
-
refetch: getCurrentUser
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
//# sourceMappingURL=use-auth.js.map
|