@oxyhq/services 5.7.4 → 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 +125 -268
- package/lib/commonjs/core/index.js +172 -0
- 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 +31 -41
- 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/index.js +1 -16
- package/lib/commonjs/ui/index.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 +172 -0
- 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 +8 -12
- 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/index.js +1 -16
- package/lib/module/ui/index.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 +67 -0
- 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 +3 -7
- 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/index.d.ts +1 -2
- package/lib/typescript/ui/index.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 -6
- package/src/core/index.ts +189 -0
- package/src/index.ts +72 -4
- package/src/node/createAuth.ts +623 -7
- package/src/node/index.ts +20 -18
- 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/index.ts +1 -19
- 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/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/__tests__/middleware.test.ts +0 -105
- package/src/__tests__/setup.ts +0 -10
- 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
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Zero-config OxyHQ Provider and Hook for React/React Native
|
|
5
|
-
*
|
|
6
|
-
* This provides a simplified, one-line setup for frontend authentication
|
|
7
|
-
* with automatic token management and API integration.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import React, { createContext, useContext, useEffect, useState, useCallback } from 'react';
|
|
11
|
-
import { OxyServices } from '../../core';
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
const OxyZeroConfigContext = /*#__PURE__*/createContext(null);
|
|
14
|
-
/**
|
|
15
|
-
* Zero-config provider for OxyHQ Services
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { OxyZeroConfigProvider } from '@oxyhq/services/ui';
|
|
20
|
-
*
|
|
21
|
-
* function App() {
|
|
22
|
-
* return (
|
|
23
|
-
* <OxyZeroConfigProvider>
|
|
24
|
-
* <MyApp />
|
|
25
|
-
* </OxyZeroConfigProvider>
|
|
26
|
-
* );
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export const OxyZeroConfigProvider = ({
|
|
31
|
-
children,
|
|
32
|
-
apiUrl,
|
|
33
|
-
onAuthChange,
|
|
34
|
-
storagePrefix = 'oxy_zero'
|
|
35
|
-
}) => {
|
|
36
|
-
// Determine API URL with fallbacks
|
|
37
|
-
const finalApiUrl = apiUrl || typeof process !== 'undefined' && process.env?.REACT_APP_OXY_API_URL || 'http://localhost:3001';
|
|
38
|
-
|
|
39
|
-
// Initialize OxyServices
|
|
40
|
-
const [api] = useState(() => new OxyServices({
|
|
41
|
-
baseURL: finalApiUrl
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
// State
|
|
45
|
-
const [user, setUser] = useState(null);
|
|
46
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
47
|
-
const [error, setError] = useState(null);
|
|
48
|
-
const isAuthenticated = user !== null;
|
|
49
|
-
|
|
50
|
-
// Storage helpers
|
|
51
|
-
const getStorageKey = key => `${storagePrefix}_${key}`;
|
|
52
|
-
const saveToStorage = useCallback((key, value) => {
|
|
53
|
-
try {
|
|
54
|
-
if (typeof localStorage !== 'undefined') {
|
|
55
|
-
localStorage.setItem(getStorageKey(key), value);
|
|
56
|
-
}
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.warn('Failed to save to storage:', error);
|
|
59
|
-
}
|
|
60
|
-
}, [storagePrefix]);
|
|
61
|
-
const getFromStorage = useCallback(key => {
|
|
62
|
-
try {
|
|
63
|
-
if (typeof localStorage !== 'undefined') {
|
|
64
|
-
return localStorage.getItem(getStorageKey(key));
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.warn('Failed to read from storage:', error);
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}, [storagePrefix]);
|
|
71
|
-
const removeFromStorage = useCallback(key => {
|
|
72
|
-
try {
|
|
73
|
-
if (typeof localStorage !== 'undefined') {
|
|
74
|
-
localStorage.removeItem(getStorageKey(key));
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.warn('Failed to remove from storage:', error);
|
|
78
|
-
}
|
|
79
|
-
}, [storagePrefix]);
|
|
80
|
-
|
|
81
|
-
// Initialize authentication state
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
const initAuth = async () => {
|
|
84
|
-
try {
|
|
85
|
-
setIsLoading(true);
|
|
86
|
-
setError(null);
|
|
87
|
-
|
|
88
|
-
// Try to restore tokens from storage
|
|
89
|
-
const savedAccessToken = getFromStorage('accessToken');
|
|
90
|
-
const savedRefreshToken = getFromStorage('refreshToken');
|
|
91
|
-
if (savedAccessToken && savedRefreshToken) {
|
|
92
|
-
// Set tokens in the API client
|
|
93
|
-
api.setTokens(savedAccessToken, savedRefreshToken);
|
|
94
|
-
|
|
95
|
-
// Validate the token
|
|
96
|
-
const isValid = await api.validate();
|
|
97
|
-
if (isValid) {
|
|
98
|
-
// Load user data
|
|
99
|
-
const currentUser = await api.getCurrentUser();
|
|
100
|
-
setUser(currentUser);
|
|
101
|
-
if (onAuthChange) {
|
|
102
|
-
onAuthChange(currentUser);
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
// Invalid token, clear storage
|
|
106
|
-
removeFromStorage('accessToken');
|
|
107
|
-
removeFromStorage('refreshToken');
|
|
108
|
-
api.clearTokens();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.warn('Failed to restore authentication:', error);
|
|
113
|
-
setError('Failed to restore authentication');
|
|
114
|
-
|
|
115
|
-
// Clear invalid tokens
|
|
116
|
-
removeFromStorage('accessToken');
|
|
117
|
-
removeFromStorage('refreshToken');
|
|
118
|
-
api.clearTokens();
|
|
119
|
-
} finally {
|
|
120
|
-
setIsLoading(false);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
initAuth();
|
|
124
|
-
}, [api, getFromStorage, removeFromStorage, onAuthChange]);
|
|
125
|
-
|
|
126
|
-
// Login method
|
|
127
|
-
const login = useCallback(async (username, password) => {
|
|
128
|
-
try {
|
|
129
|
-
setIsLoading(true);
|
|
130
|
-
setError(null);
|
|
131
|
-
const response = await api.login(username, password);
|
|
132
|
-
|
|
133
|
-
// Save tokens to storage
|
|
134
|
-
if (response.accessToken) {
|
|
135
|
-
saveToStorage('accessToken', response.accessToken);
|
|
136
|
-
}
|
|
137
|
-
if (response.refreshToken) {
|
|
138
|
-
saveToStorage('refreshToken', response.refreshToken);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Update state
|
|
142
|
-
setUser(response.user);
|
|
143
|
-
if (onAuthChange) {
|
|
144
|
-
onAuthChange(response.user);
|
|
145
|
-
}
|
|
146
|
-
return response.user;
|
|
147
|
-
} catch (error) {
|
|
148
|
-
const errorMessage = error.message || 'Login failed';
|
|
149
|
-
setError(errorMessage);
|
|
150
|
-
throw new Error(errorMessage);
|
|
151
|
-
} finally {
|
|
152
|
-
setIsLoading(false);
|
|
153
|
-
}
|
|
154
|
-
}, [api, saveToStorage, onAuthChange]);
|
|
155
|
-
|
|
156
|
-
// Logout method
|
|
157
|
-
const logout = useCallback(async () => {
|
|
158
|
-
try {
|
|
159
|
-
setIsLoading(true);
|
|
160
|
-
await api.logout();
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.warn('Logout API call failed:', error);
|
|
163
|
-
} finally {
|
|
164
|
-
// Always clean up local state and storage
|
|
165
|
-
removeFromStorage('accessToken');
|
|
166
|
-
removeFromStorage('refreshToken');
|
|
167
|
-
api.clearTokens();
|
|
168
|
-
setUser(null);
|
|
169
|
-
setError(null);
|
|
170
|
-
setIsLoading(false);
|
|
171
|
-
if (onAuthChange) {
|
|
172
|
-
onAuthChange(null);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}, [api, removeFromStorage, onAuthChange]);
|
|
176
|
-
|
|
177
|
-
// Register method
|
|
178
|
-
const register = useCallback(async (username, email, password) => {
|
|
179
|
-
try {
|
|
180
|
-
setIsLoading(true);
|
|
181
|
-
setError(null);
|
|
182
|
-
const response = await api.signUp(username, email, password);
|
|
183
|
-
|
|
184
|
-
// Save token from registration
|
|
185
|
-
if (response.token) {
|
|
186
|
-
saveToStorage('accessToken', response.token);
|
|
187
|
-
// Note: signUp doesn't return refreshToken in current API
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Update state
|
|
191
|
-
setUser(response.user);
|
|
192
|
-
if (onAuthChange) {
|
|
193
|
-
onAuthChange(response.user);
|
|
194
|
-
}
|
|
195
|
-
return response.user;
|
|
196
|
-
} catch (error) {
|
|
197
|
-
const errorMessage = error.message || 'Registration failed';
|
|
198
|
-
setError(errorMessage);
|
|
199
|
-
throw new Error(errorMessage);
|
|
200
|
-
} finally {
|
|
201
|
-
setIsLoading(false);
|
|
202
|
-
}
|
|
203
|
-
}, [api, saveToStorage, onAuthChange]);
|
|
204
|
-
const contextValue = {
|
|
205
|
-
user,
|
|
206
|
-
isAuthenticated,
|
|
207
|
-
isLoading,
|
|
208
|
-
error,
|
|
209
|
-
login,
|
|
210
|
-
logout,
|
|
211
|
-
register,
|
|
212
|
-
api
|
|
213
|
-
};
|
|
214
|
-
return /*#__PURE__*/_jsx(OxyZeroConfigContext.Provider, {
|
|
215
|
-
value: contextValue,
|
|
216
|
-
children: children
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Zero-config hook for OxyHQ Services
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```tsx
|
|
225
|
-
* function MyComponent() {
|
|
226
|
-
* const { user, login, logout, isAuthenticated } = useOxyZeroConfig();
|
|
227
|
-
*
|
|
228
|
-
* const handleLogin = () => {
|
|
229
|
-
* login('username', 'password');
|
|
230
|
-
* };
|
|
231
|
-
*
|
|
232
|
-
* if (isAuthenticated) {
|
|
233
|
-
* return <div>Welcome, {user?.username}!</div>;
|
|
234
|
-
* }
|
|
235
|
-
*
|
|
236
|
-
* return <button onClick={handleLogin}>Login</button>;
|
|
237
|
-
* }
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
export const useOxyZeroConfig = () => {
|
|
241
|
-
const context = useContext(OxyZeroConfigContext);
|
|
242
|
-
if (!context) {
|
|
243
|
-
throw new Error('useOxyZeroConfig must be used within an OxyZeroConfigProvider');
|
|
244
|
-
}
|
|
245
|
-
return context;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Hook for automatic API client with authentication
|
|
250
|
-
* This automatically includes the auth token in requests
|
|
251
|
-
*
|
|
252
|
-
* @example
|
|
253
|
-
* ```tsx
|
|
254
|
-
* function ProfileComponent() {
|
|
255
|
-
* const api = useOxyApi();
|
|
256
|
-
*
|
|
257
|
-
* const updateProfile = async (data) => {
|
|
258
|
-
* const user = await api.updateProfile(data);
|
|
259
|
-
* // Token is automatically included
|
|
260
|
-
* };
|
|
261
|
-
* }
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
export const useOxyApi = () => {
|
|
265
|
-
const {
|
|
266
|
-
api
|
|
267
|
-
} = useOxyZeroConfig();
|
|
268
|
-
return api;
|
|
269
|
-
};
|
|
270
|
-
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useContext","useEffect","useState","useCallback","OxyServices","jsx","_jsx","OxyZeroConfigContext","OxyZeroConfigProvider","children","apiUrl","onAuthChange","storagePrefix","finalApiUrl","process","env","REACT_APP_OXY_API_URL","api","baseURL","user","setUser","isLoading","setIsLoading","error","setError","isAuthenticated","getStorageKey","key","saveToStorage","value","localStorage","setItem","console","warn","getFromStorage","getItem","removeFromStorage","removeItem","initAuth","savedAccessToken","savedRefreshToken","setTokens","isValid","validate","currentUser","getCurrentUser","clearTokens","login","username","password","response","accessToken","refreshToken","errorMessage","message","Error","logout","register","email","signUp","token","contextValue","Provider","useOxyZeroConfig","context","useOxyApi"],"sourceRoot":"../../../../src","sources":["ui/zero-config/provider.tsx"],"mapp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UAAU,CAACO,oBAAoB,CAAC;EAChD,IAAI,CAACyD,OAAO,EAAE;IACZ,MAAM,IAAIT,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,OAAOS,OAAO;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAmB;EAC1C,MAAM;IAAEhD;EAAI,CAAC,GAAG8C,gBAAgB,CAAC,CAAC;EAClC,OAAO9C,GAAG;AACZ,CAAC","ignoreList":[]}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zero-config Express middleware for OxyHQ Services authentication
|
|
3
|
-
*
|
|
4
|
-
* This provides a simple, one-line solution for adding authentication to Express apps.
|
|
5
|
-
* Simply import and use: app.use('/api', createOxyAuth())
|
|
6
|
-
*/
|
|
7
|
-
import { ApiError } from '../models/interfaces';
|
|
8
|
-
export interface OxyAuthConfig {
|
|
9
|
-
/** Base URL of your Oxy API server */
|
|
10
|
-
baseURL?: string;
|
|
11
|
-
/** Whether to load full user data (default: true) */
|
|
12
|
-
loadUser?: boolean;
|
|
13
|
-
/** Routes that don't require authentication */
|
|
14
|
-
publicPaths?: string[];
|
|
15
|
-
/** Custom error handler */
|
|
16
|
-
onError?: (error: ApiError, req: any, res: any) => void;
|
|
17
|
-
}
|
|
18
|
-
export interface AuthenticatedRequest {
|
|
19
|
-
user?: any;
|
|
20
|
-
userId?: string;
|
|
21
|
-
accessToken?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates zero-config authentication middleware for Express.js
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import express from 'express';
|
|
29
|
-
* import { createOxyAuth } from '@oxyhq/services/node';
|
|
30
|
-
*
|
|
31
|
-
* const app = express();
|
|
32
|
-
*
|
|
33
|
-
* // Zero-config auth for all /api routes
|
|
34
|
-
* app.use('/api', createOxyAuth());
|
|
35
|
-
*
|
|
36
|
-
* // Now all routes under /api automatically have req.user available
|
|
37
|
-
* app.get('/api/profile', (req, res) => {
|
|
38
|
-
* res.json({ user: req.user }); // req.user is automatically available
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function createOxyAuth(config?: OxyAuthConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
43
|
-
/**
|
|
44
|
-
* Creates optional authentication middleware
|
|
45
|
-
* This middleware will attach user data if a valid token is present, but won't fail if missing
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { createOptionalOxyAuth } from '@oxyhq/services/node';
|
|
50
|
-
*
|
|
51
|
-
* app.use('/api', createOptionalOxyAuth());
|
|
52
|
-
*
|
|
53
|
-
* app.get('/api/content', (req, res) => {
|
|
54
|
-
* if (req.user) {
|
|
55
|
-
* // User is authenticated, show personalized content
|
|
56
|
-
* res.json({ content: 'personalized', user: req.user });
|
|
57
|
-
* } else {
|
|
58
|
-
* // Anonymous user, show public content
|
|
59
|
-
* res.json({ content: 'public' });
|
|
60
|
-
* }
|
|
61
|
-
* });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare function createOptionalOxyAuth(config?: OxyAuthConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
65
|
-
/**
|
|
66
|
-
* Utility function to quickly set up a complete Express app with authentication
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* import { createOxyExpressApp } from '@oxyhq/services/node';
|
|
71
|
-
*
|
|
72
|
-
* const app = createOxyExpressApp();
|
|
73
|
-
*
|
|
74
|
-
* // All routes automatically have authentication and req.user available
|
|
75
|
-
* app.get('/api/profile', (req, res) => {
|
|
76
|
-
* res.json({ user: req.user });
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* app.listen(3000);
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare function createOxyExpressApp(config?: OxyAuthConfig & {
|
|
83
|
-
/** Express app configuration */
|
|
84
|
-
cors?: boolean;
|
|
85
|
-
/** JSON body parser limit */
|
|
86
|
-
jsonLimit?: string;
|
|
87
|
-
/** Additional middleware to apply */
|
|
88
|
-
middleware?: any[];
|
|
89
|
-
}): void;
|
|
90
|
-
export { OxyServices } from '../core';
|
|
91
|
-
export * from '../models/interfaces';
|
|
92
|
-
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/node/middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,aAAkB,IAUxC,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,kBA+E5C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,aAAkB,IAQhD,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,kBAgC5C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,aAAa,GAAG;IAC1D,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;CACf,QAKL;AAGD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/zero-config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAChC,MAAM,YAAY,CAAC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zero-config OxyHQ Provider and Hook for React/React Native
|
|
3
|
-
*
|
|
4
|
-
* This provides a simplified, one-line setup for frontend authentication
|
|
5
|
-
* with automatic token management and API integration.
|
|
6
|
-
*/
|
|
7
|
-
import React, { ReactNode } from 'react';
|
|
8
|
-
import { OxyServices } from '../../core';
|
|
9
|
-
import { User } from '../../models/interfaces';
|
|
10
|
-
export interface OxyZeroConfigState {
|
|
11
|
-
user: User | null;
|
|
12
|
-
isAuthenticated: boolean;
|
|
13
|
-
isLoading: boolean;
|
|
14
|
-
error: string | null;
|
|
15
|
-
login: (username: string, password: string) => Promise<User>;
|
|
16
|
-
logout: () => Promise<void>;
|
|
17
|
-
register: (username: string, email: string, password: string) => Promise<User>;
|
|
18
|
-
api: OxyServices;
|
|
19
|
-
}
|
|
20
|
-
export interface OxyZeroConfigProviderProps {
|
|
21
|
-
children: ReactNode;
|
|
22
|
-
/** Base URL of your Oxy API server (defaults to process.env.REACT_APP_OXY_API_URL or http://localhost:3001) */
|
|
23
|
-
apiUrl?: string;
|
|
24
|
-
/** Called when authentication state changes */
|
|
25
|
-
onAuthChange?: (user: User | null) => void;
|
|
26
|
-
/** Storage key prefix (default: 'oxy_zero') */
|
|
27
|
-
storagePrefix?: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Zero-config provider for OxyHQ Services
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* import { OxyZeroConfigProvider } from '@oxyhq/services/ui';
|
|
35
|
-
*
|
|
36
|
-
* function App() {
|
|
37
|
-
* return (
|
|
38
|
-
* <OxyZeroConfigProvider>
|
|
39
|
-
* <MyApp />
|
|
40
|
-
* </OxyZeroConfigProvider>
|
|
41
|
-
* );
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare const OxyZeroConfigProvider: React.FC<OxyZeroConfigProviderProps>;
|
|
46
|
-
/**
|
|
47
|
-
* Zero-config hook for OxyHQ Services
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* function MyComponent() {
|
|
52
|
-
* const { user, login, logout, isAuthenticated } = useOxyZeroConfig();
|
|
53
|
-
*
|
|
54
|
-
* const handleLogin = () => {
|
|
55
|
-
* login('username', 'password');
|
|
56
|
-
* };
|
|
57
|
-
*
|
|
58
|
-
* if (isAuthenticated) {
|
|
59
|
-
* return <div>Welcome, {user?.username}!</div>;
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* return <button onClick={handleLogin}>Login</button>;
|
|
63
|
-
* }
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare const useOxyZeroConfig: () => OxyZeroConfigState;
|
|
67
|
-
/**
|
|
68
|
-
* Hook for automatic API client with authentication
|
|
69
|
-
* This automatically includes the auth token in requests
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```tsx
|
|
73
|
-
* function ProfileComponent() {
|
|
74
|
-
* const api = useOxyApi();
|
|
75
|
-
*
|
|
76
|
-
* const updateProfile = async (data) => {
|
|
77
|
-
* const user = await api.updateProfile(data);
|
|
78
|
-
* // Token is automatically included
|
|
79
|
-
* };
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare const useOxyApi: () => OxyServices;
|
|
84
|
-
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/ui/zero-config/provider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAkD,SAAS,EAAe,MAAM,OAAO,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,IAAI,EAAiB,MAAM,yBAAyB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAGrB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAG/E,GAAG,EAAE,WAAW,CAAC;CAClB;AAID,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,SAAS,CAAC;IACpB,+GAA+G;IAC/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3C,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CA6MtE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gBAAgB,QAAO,kBAMnC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,QAAO,WAG5B,CAAC"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { OxyServices } from '../core';
|
|
2
|
-
import jwt from 'jsonwebtoken';
|
|
3
|
-
|
|
4
|
-
// Mock axios
|
|
5
|
-
jest.mock('axios', () => ({
|
|
6
|
-
create: jest.fn(() => ({
|
|
7
|
-
get: jest.fn(),
|
|
8
|
-
post: jest.fn(),
|
|
9
|
-
put: jest.fn(),
|
|
10
|
-
delete: jest.fn(),
|
|
11
|
-
interceptors: {
|
|
12
|
-
request: { use: jest.fn() },
|
|
13
|
-
response: { use: jest.fn() }
|
|
14
|
-
},
|
|
15
|
-
defaults: { baseURL: 'http://localhost:3001' }
|
|
16
|
-
}))
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
describe('createAuthenticateTokenMiddleware', () => {
|
|
20
|
-
let oxyServices: OxyServices;
|
|
21
|
-
let mockReq: any;
|
|
22
|
-
let mockRes: any;
|
|
23
|
-
let mockNext: any;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
oxyServices = new OxyServices({ baseURL: 'http://localhost:3001' });
|
|
27
|
-
|
|
28
|
-
mockReq = {
|
|
29
|
-
headers: {
|
|
30
|
-
authorization: 'Bearer test-token'
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
mockRes = {
|
|
35
|
-
status: jest.fn().mockReturnThis(),
|
|
36
|
-
json: jest.fn()
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
mockNext = jest.fn();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should create middleware function', () => {
|
|
43
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware();
|
|
44
|
-
expect(typeof middleware).toBe('function');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should handle missing token', async () => {
|
|
48
|
-
mockReq.headers.authorization = undefined;
|
|
49
|
-
|
|
50
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware();
|
|
51
|
-
await middleware(mockReq, mockRes, mockNext);
|
|
52
|
-
|
|
53
|
-
expect(mockRes.status).toHaveBeenCalledWith(401);
|
|
54
|
-
expect(mockRes.json).toHaveBeenCalledWith({
|
|
55
|
-
message: 'Access token required',
|
|
56
|
-
code: 'MISSING_TOKEN'
|
|
57
|
-
});
|
|
58
|
-
expect(mockNext).not.toHaveBeenCalled();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should handle invalid authorization header format', async () => {
|
|
62
|
-
mockReq.headers.authorization = 'InvalidFormat test-token';
|
|
63
|
-
|
|
64
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware();
|
|
65
|
-
await middleware(mockReq, mockRes, mockNext);
|
|
66
|
-
|
|
67
|
-
expect(mockRes.status).toHaveBeenCalledWith(401);
|
|
68
|
-
expect(mockRes.json).toHaveBeenCalledWith({
|
|
69
|
-
message: 'Access token required',
|
|
70
|
-
code: 'MISSING_TOKEN'
|
|
71
|
-
});
|
|
72
|
-
expect(mockNext).not.toHaveBeenCalled();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should call custom error handler when provided', async () => {
|
|
76
|
-
mockReq.headers.authorization = undefined;
|
|
77
|
-
const customErrorHandler = jest.fn();
|
|
78
|
-
|
|
79
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware({
|
|
80
|
-
onError: customErrorHandler
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await middleware(mockReq, mockRes, mockNext);
|
|
84
|
-
|
|
85
|
-
expect(customErrorHandler).toHaveBeenCalledWith({
|
|
86
|
-
message: 'Access token required',
|
|
87
|
-
code: 'MISSING_TOKEN',
|
|
88
|
-
status: 401
|
|
89
|
-
});
|
|
90
|
-
expect(mockNext).not.toHaveBeenCalled();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should set loadFullUser to true by default', () => {
|
|
94
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware();
|
|
95
|
-
// This is an internal implementation detail, but we can verify the function exists
|
|
96
|
-
expect(typeof middleware).toBe('function');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should accept loadFullUser option', () => {
|
|
100
|
-
const middleware = oxyServices.createAuthenticateTokenMiddleware({
|
|
101
|
-
loadFullUser: false
|
|
102
|
-
});
|
|
103
|
-
expect(typeof middleware).toBe('function');
|
|
104
|
-
});
|
|
105
|
-
});
|