@oxyhq/services 10.2.9 → 10.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/ui/components/ActingAsBanner.js +2 -1
- package/lib/commonjs/ui/components/ActingAsBanner.js.map +1 -1
- package/lib/commonjs/ui/components/StepBasedScreen.js +19 -10
- package/lib/commonjs/ui/components/StepBasedScreen.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +38 -122
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +9 -7
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/useDeviceAccounts.js +20 -25
- package/lib/commonjs/ui/hooks/useDeviceAccounts.js.map +1 -1
- package/lib/commonjs/ui/hooks/useProfileEditing.js +19 -10
- package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/commonjs/ui/screens/AppInfoScreen.js +1 -2
- package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AvatarCropScreen.js +52 -4
- package/lib/commonjs/ui/screens/AvatarCropScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ConnectedAppsScreen.js +1 -2
- package/lib/commonjs/ui/screens/ConnectedAppsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +11 -13
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FeedbackScreen.js +2 -3
- package/lib/commonjs/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/HelpSupportScreen.js +2 -2
- package/lib/commonjs/ui/screens/HelpSupportScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/HistoryViewScreen.js +2 -2
- package/lib/commonjs/ui/screens/HistoryViewScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/LanguageSelectorScreen.js +2 -3
- package/lib/commonjs/ui/screens/LanguageSelectorScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/LegalDocumentsScreen.js +2 -2
- package/lib/commonjs/ui/screens/LegalDocumentsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ManageAccountScreen.js +1 -2
- package/lib/commonjs/ui/screens/ManageAccountScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/NotificationsScreen.js +2 -2
- package/lib/commonjs/ui/screens/NotificationsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js +2 -2
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PreferencesScreen.js +2 -2
- package/lib/commonjs/ui/screens/PreferencesScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +4 -3
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SavesCollectionsScreen.js +3 -4
- package/lib/commonjs/ui/screens/SavesCollectionsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/trust/TrustCenterScreen.js +2 -2
- package/lib/commonjs/ui/screens/trust/TrustCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/trust/TrustFAQScreen.js +2 -2
- package/lib/commonjs/ui/screens/trust/TrustFAQScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/trust/TrustRewardsScreen.js +2 -2
- package/lib/commonjs/ui/screens/trust/TrustRewardsScreen.js.map +1 -1
- package/lib/commonjs/ui/stores/authStore.js.map +1 -1
- package/lib/commonjs/ui/utils/avatarUtils.js +1 -1
- package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
- package/lib/module/ui/components/ActingAsBanner.js +2 -1
- package/lib/module/ui/components/ActingAsBanner.js.map +1 -1
- package/lib/module/ui/components/StepBasedScreen.js +19 -10
- package/lib/module/ui/components/StepBasedScreen.js.map +1 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +38 -122
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useAccountMutations.js +9 -7
- package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/module/ui/hooks/useDeviceAccounts.js +20 -25
- package/lib/module/ui/hooks/useDeviceAccounts.js.map +1 -1
- package/lib/module/ui/hooks/useProfileEditing.js +19 -10
- package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/module/ui/screens/AppInfoScreen.js +1 -1
- package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/module/ui/screens/AvatarCropScreen.js +52 -4
- package/lib/module/ui/screens/AvatarCropScreen.js.map +1 -1
- package/lib/module/ui/screens/ConnectedAppsScreen.js +1 -1
- package/lib/module/ui/screens/ConnectedAppsScreen.js.map +1 -1
- package/lib/module/ui/screens/EditProfileFieldScreen.js +10 -11
- package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/module/ui/screens/FeedbackScreen.js +1 -1
- package/lib/module/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/module/ui/screens/HelpSupportScreen.js +1 -1
- package/lib/module/ui/screens/HelpSupportScreen.js.map +1 -1
- package/lib/module/ui/screens/HistoryViewScreen.js +1 -1
- package/lib/module/ui/screens/HistoryViewScreen.js.map +1 -1
- package/lib/module/ui/screens/LanguageSelectorScreen.js +1 -1
- package/lib/module/ui/screens/LanguageSelectorScreen.js.map +1 -1
- package/lib/module/ui/screens/LegalDocumentsScreen.js +1 -1
- package/lib/module/ui/screens/LegalDocumentsScreen.js.map +1 -1
- package/lib/module/ui/screens/ManageAccountScreen.js +1 -1
- package/lib/module/ui/screens/ManageAccountScreen.js.map +1 -1
- package/lib/module/ui/screens/NotificationsScreen.js +1 -1
- package/lib/module/ui/screens/NotificationsScreen.js.map +1 -1
- package/lib/module/ui/screens/PaymentGatewayScreen.js +1 -1
- package/lib/module/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/module/ui/screens/PreferencesScreen.js +1 -1
- package/lib/module/ui/screens/PreferencesScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +5 -4
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/screens/SavesCollectionsScreen.js +2 -3
- package/lib/module/ui/screens/SavesCollectionsScreen.js.map +1 -1
- package/lib/module/ui/screens/trust/TrustCenterScreen.js +1 -1
- package/lib/module/ui/screens/trust/TrustCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/trust/TrustFAQScreen.js +1 -1
- package/lib/module/ui/screens/trust/TrustFAQScreen.js.map +1 -1
- package/lib/module/ui/screens/trust/TrustRewardsScreen.js +1 -1
- package/lib/module/ui/screens/trust/TrustRewardsScreen.js.map +1 -1
- package/lib/module/ui/stores/authStore.js.map +1 -1
- package/lib/module/ui/utils/avatarUtils.js +1 -1
- package/lib/module/ui/utils/avatarUtils.js.map +1 -1
- package/lib/typescript/commonjs/ui/components/ActingAsBanner.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/StepBasedScreen.d.ts +5 -3
- package/lib/typescript/commonjs/ui/components/StepBasedScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts +1 -1
- package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts +52 -6
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useDeviceAccounts.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useProfileEditing.d.ts +22 -18
- package/lib/typescript/commonjs/ui/hooks/useProfileEditing.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/AvatarCropScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/SavesCollectionsScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/stores/authStore.d.ts +2 -10
- package/lib/typescript/commonjs/ui/stores/authStore.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/types/navigation.d.ts +0 -1
- package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/avatarUtils.d.ts +2 -1
- package/lib/typescript/commonjs/ui/utils/avatarUtils.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ActingAsBanner.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/StepBasedScreen.d.ts +5 -3
- package/lib/typescript/module/ui/components/StepBasedScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts +1 -1
- package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts +52 -6
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useDeviceAccounts.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useProfileEditing.d.ts +22 -18
- package/lib/typescript/module/ui/hooks/useProfileEditing.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/AvatarCropScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/SavesCollectionsScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/stores/authStore.d.ts +2 -10
- package/lib/typescript/module/ui/stores/authStore.d.ts.map +1 -1
- package/lib/typescript/module/ui/types/navigation.d.ts +0 -1
- package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/avatarUtils.d.ts +2 -1
- package/lib/typescript/module/ui/utils/avatarUtils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/ui/components/ActingAsBanner.tsx +2 -4
- package/src/ui/components/StepBasedScreen.tsx +37 -22
- package/src/ui/context/hooks/useAuthOperations.ts +51 -144
- package/src/ui/hooks/mutations/useAccountMutations.ts +9 -8
- package/src/ui/hooks/useDeviceAccounts.ts +20 -24
- package/src/ui/hooks/useProfileEditing.ts +43 -30
- package/src/ui/screens/AppInfoScreen.tsx +1 -1
- package/src/ui/screens/AvatarCropScreen.tsx +67 -4
- package/src/ui/screens/ConnectedAppsScreen.tsx +1 -1
- package/src/ui/screens/EditProfileFieldScreen.tsx +24 -14
- package/src/ui/screens/FeedbackScreen.tsx +1 -1
- package/src/ui/screens/HelpSupportScreen.tsx +1 -1
- package/src/ui/screens/HistoryViewScreen.tsx +1 -1
- package/src/ui/screens/LanguageSelectorScreen.tsx +1 -1
- package/src/ui/screens/LegalDocumentsScreen.tsx +1 -1
- package/src/ui/screens/ManageAccountScreen.tsx +1 -1
- package/src/ui/screens/NotificationsScreen.tsx +1 -1
- package/src/ui/screens/PaymentGatewayScreen.tsx +1 -1
- package/src/ui/screens/PreferencesScreen.tsx +1 -1
- package/src/ui/screens/ProfileScreen.tsx +4 -4
- package/src/ui/screens/SavesCollectionsScreen.tsx +3 -6
- package/src/ui/screens/trust/TrustCenterScreen.tsx +1 -1
- package/src/ui/screens/trust/TrustFAQScreen.tsx +1 -1
- package/src/ui/screens/trust/TrustRewardsScreen.tsx +1 -1
- package/src/ui/stores/authStore.ts +4 -13
- package/src/ui/types/navigation.ts +0 -4
- package/src/ui/utils/avatarUtils.ts +3 -2
- package/lib/commonjs/ui/styles/spacing.js +0 -68
- package/lib/commonjs/ui/styles/spacing.js.map +0 -1
- package/lib/commonjs/ui/utils/themeUtils.js +0 -37
- package/lib/commonjs/ui/utils/themeUtils.js.map +0 -1
- package/lib/module/ui/styles/spacing.js +0 -16
- package/lib/module/ui/styles/spacing.js.map +0 -1
- package/lib/module/ui/utils/themeUtils.js +0 -13
- package/lib/module/ui/utils/themeUtils.js.map +0 -1
- package/lib/typescript/commonjs/ui/styles/spacing.d.ts +0 -13
- package/lib/typescript/commonjs/ui/styles/spacing.d.ts.map +0 -1
- package/lib/typescript/commonjs/ui/utils/themeUtils.d.ts +0 -11
- package/lib/typescript/commonjs/ui/utils/themeUtils.d.ts.map +0 -1
- package/lib/typescript/module/ui/styles/spacing.d.ts +0 -13
- package/lib/typescript/module/ui/styles/spacing.d.ts.map +0 -1
- package/lib/typescript/module/ui/utils/themeUtils.d.ts +0 -11
- package/lib/typescript/module/ui/utils/themeUtils.d.ts.map +0 -1
- package/src/ui/styles/spacing.ts +0 -22
- package/src/ui/utils/themeUtils.ts +0 -18
|
@@ -11,11 +11,6 @@ import { SignatureService } from '@oxyhq/core';
|
|
|
11
11
|
import { isWebBrowser } from '../../hooks/useWebSSO';
|
|
12
12
|
import { clearActiveAuthuser, clearSsoBounceState } from '../../utils/activeAuthuser';
|
|
13
13
|
|
|
14
|
-
/** Type guard for error objects with optional code and status properties */
|
|
15
|
-
function isErrorWithCodeOrStatus(error: unknown): error is { code?: string; status?: number; message?: string } {
|
|
16
|
-
return typeof error === 'object' && error !== null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
14
|
export interface UseAuthOperationsOptions {
|
|
20
15
|
oxyServices: OxyServices;
|
|
21
16
|
storage: StorageInterface | null;
|
|
@@ -55,7 +50,6 @@ const LOGOUT_ALL_ERROR_CODE = 'LOGOUT_ALL_ERROR';
|
|
|
55
50
|
*/
|
|
56
51
|
export const useAuthOperations = ({
|
|
57
52
|
oxyServices,
|
|
58
|
-
storage,
|
|
59
53
|
sessions,
|
|
60
54
|
activeSessionId,
|
|
61
55
|
setActiveSessionId,
|
|
@@ -77,7 +71,7 @@ export const useAuthOperations = ({
|
|
|
77
71
|
sessionsRef.current = sessions;
|
|
78
72
|
|
|
79
73
|
/**
|
|
80
|
-
* Internal function to perform challenge-response sign in
|
|
74
|
+
* Internal function to perform challenge-response sign in.
|
|
81
75
|
*/
|
|
82
76
|
const performSignIn = useCallback(
|
|
83
77
|
async (publicKey: string): Promise<User> => {
|
|
@@ -86,36 +80,8 @@ export const useAuthOperations = ({
|
|
|
86
80
|
const deviceInfo = await DeviceManager.getDeviceInfo();
|
|
87
81
|
const deviceName = deviceInfo.deviceName || DeviceManager.getDefaultDeviceName();
|
|
88
82
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Try to request challenge from server (online)
|
|
93
|
-
try {
|
|
94
|
-
const challengeResponse = await oxyServices.requestChallenge(publicKey);
|
|
95
|
-
challenge = challengeResponse.challenge;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
// Network error - generate challenge locally for offline sign-in
|
|
98
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
99
|
-
const isNetworkError =
|
|
100
|
-
errorMessage.includes('Network') ||
|
|
101
|
-
errorMessage.includes('network') ||
|
|
102
|
-
errorMessage.includes('Failed to fetch') ||
|
|
103
|
-
errorMessage.includes('fetch failed') ||
|
|
104
|
-
(isErrorWithCodeOrStatus(error) && error.code === 'NETWORK_ERROR') ||
|
|
105
|
-
(isErrorWithCodeOrStatus(error) && error.status === 0);
|
|
106
|
-
|
|
107
|
-
if (isNetworkError) {
|
|
108
|
-
if (__DEV__ && logger) {
|
|
109
|
-
logger('Network unavailable, performing offline sign-in');
|
|
110
|
-
}
|
|
111
|
-
// Generate challenge locally
|
|
112
|
-
challenge = await SignatureService.generateChallenge();
|
|
113
|
-
isOffline = true;
|
|
114
|
-
} else {
|
|
115
|
-
// Re-throw non-network errors
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
83
|
+
const challengeResponse = await oxyServices.requestChallenge(publicKey);
|
|
84
|
+
const challenge = challengeResponse.challenge;
|
|
119
85
|
|
|
120
86
|
// Note: Biometric authentication check should be handled by the app layer
|
|
121
87
|
// (e.g., accounts app) before calling signIn. The biometric preference is stored
|
|
@@ -127,123 +93,65 @@ export const useAuthOperations = ({
|
|
|
127
93
|
let fullUser: User;
|
|
128
94
|
let sessionResponse: SessionLoginResponse;
|
|
129
95
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
user: {
|
|
155
|
-
id: publicKey,
|
|
156
|
-
username: '',
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// Store offline session locally
|
|
161
|
-
const offlineSession: ClientSession = {
|
|
162
|
-
sessionId: localSessionId,
|
|
163
|
-
deviceId: localDeviceId,
|
|
164
|
-
expiresAt,
|
|
165
|
-
lastActive: new Date().toISOString(),
|
|
166
|
-
userId: publicKey,
|
|
167
|
-
isCurrent: true,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
setActiveSessionId(localSessionId);
|
|
171
|
-
await saveActiveSessionId(localSessionId);
|
|
172
|
-
updateSessions([offlineSession], { merge: true });
|
|
173
|
-
|
|
174
|
-
// Mark session as offline for later sync
|
|
175
|
-
if (storage) {
|
|
176
|
-
await storage.setItem(`oxy_session_${localSessionId}_offline`, 'true');
|
|
177
|
-
}
|
|
178
|
-
|
|
96
|
+
// `verifyChallenge` plants the first access token internally, mirroring
|
|
97
|
+
// `claimSessionByToken`, so the client is authenticated as soon as this
|
|
98
|
+
// resolves.
|
|
99
|
+
sessionResponse = await oxyServices.verifyChallenge(
|
|
100
|
+
publicKey,
|
|
101
|
+
challenge,
|
|
102
|
+
signature,
|
|
103
|
+
timestamp,
|
|
104
|
+
deviceName,
|
|
105
|
+
deviceFingerprint,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// Get full user data
|
|
109
|
+
fullUser = await oxyServices.getUserBySession(sessionResponse.sessionId);
|
|
110
|
+
|
|
111
|
+
// Fetch device sessions
|
|
112
|
+
let allDeviceSessions: ClientSession[] = [];
|
|
113
|
+
try {
|
|
114
|
+
allDeviceSessions = await fetchSessionsWithFallback(oxyServices, sessionResponse.sessionId, {
|
|
115
|
+
fallbackDeviceId: sessionResponse.deviceId,
|
|
116
|
+
fallbackUserId: fullUser.id,
|
|
117
|
+
logger,
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
179
120
|
if (__DEV__ && logger) {
|
|
180
|
-
logger('
|
|
121
|
+
logger('Failed to fetch device sessions after login', error);
|
|
181
122
|
}
|
|
182
|
-
}
|
|
183
|
-
// Online sign-in: use normal flow.
|
|
184
|
-
// Verify and create session. `verifyChallenge` plants the first
|
|
185
|
-
// access token (and refresh token) from the `/auth/verify` response
|
|
186
|
-
// body internally — mirroring `claimSessionByToken` — so the client is
|
|
187
|
-
// authenticated as soon as this resolves. Session IDs are not public
|
|
188
|
-
// token-minting credentials; a token-less verify response simply leaves
|
|
189
|
-
// the client without a bearer here.
|
|
190
|
-
sessionResponse = await oxyServices.verifyChallenge(
|
|
191
|
-
publicKey,
|
|
192
|
-
challenge,
|
|
193
|
-
signature,
|
|
194
|
-
timestamp,
|
|
195
|
-
deviceName,
|
|
196
|
-
deviceFingerprint,
|
|
197
|
-
);
|
|
123
|
+
}
|
|
198
124
|
|
|
199
|
-
|
|
200
|
-
|
|
125
|
+
// Check for existing session for same user and switch to it to avoid duplicates
|
|
126
|
+
const existingSession = allDeviceSessions.find(
|
|
127
|
+
(session) =>
|
|
128
|
+
session.userId?.toString() === fullUser.id?.toString() &&
|
|
129
|
+
session.sessionId !== sessionResponse.sessionId,
|
|
130
|
+
);
|
|
201
131
|
|
|
202
|
-
|
|
203
|
-
|
|
132
|
+
if (existingSession) {
|
|
133
|
+
// Switch to existing session instead of creating duplicate
|
|
204
134
|
try {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
logger,
|
|
209
|
-
});
|
|
210
|
-
} catch (error) {
|
|
135
|
+
await oxyServices.logoutSession(sessionResponse.sessionId, sessionResponse.sessionId);
|
|
136
|
+
} catch (logoutError) {
|
|
137
|
+
// Non-critical - continue to switch session even if logout fails
|
|
211
138
|
if (__DEV__ && logger) {
|
|
212
|
-
logger('Failed to
|
|
139
|
+
logger('Failed to logout duplicate session, continuing with switch', logoutError);
|
|
213
140
|
}
|
|
214
141
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
session.userId?.toString() === fullUser.id?.toString() &&
|
|
220
|
-
session.sessionId !== sessionResponse.sessionId,
|
|
142
|
+
await switchSession(existingSession.sessionId);
|
|
143
|
+
updateSessions(
|
|
144
|
+
allDeviceSessions.filter((session) => session.sessionId !== sessionResponse.sessionId),
|
|
145
|
+
{ merge: false },
|
|
221
146
|
);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// Switch to existing session instead of creating duplicate
|
|
225
|
-
try {
|
|
226
|
-
await oxyServices.logoutSession(sessionResponse.sessionId, sessionResponse.sessionId);
|
|
227
|
-
} catch (logoutError) {
|
|
228
|
-
// Non-critical - continue to switch session even if logout fails
|
|
229
|
-
if (__DEV__ && logger) {
|
|
230
|
-
logger('Failed to logout duplicate session, continuing with switch', logoutError);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
await switchSession(existingSession.sessionId);
|
|
234
|
-
updateSessions(
|
|
235
|
-
allDeviceSessions.filter((session) => session.sessionId !== sessionResponse.sessionId),
|
|
236
|
-
{ merge: false },
|
|
237
|
-
);
|
|
238
|
-
onAuthStateChange?.(fullUser);
|
|
239
|
-
return fullUser;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
setActiveSessionId(sessionResponse.sessionId);
|
|
243
|
-
await saveActiveSessionId(sessionResponse.sessionId);
|
|
244
|
-
updateSessions(allDeviceSessions, { merge: true });
|
|
147
|
+
onAuthStateChange?.(fullUser);
|
|
148
|
+
return fullUser;
|
|
245
149
|
}
|
|
246
150
|
|
|
151
|
+
setActiveSessionId(sessionResponse.sessionId);
|
|
152
|
+
await saveActiveSessionId(sessionResponse.sessionId);
|
|
153
|
+
updateSessions(allDeviceSessions, { merge: true });
|
|
154
|
+
|
|
247
155
|
await applyLanguagePreference(fullUser);
|
|
248
156
|
loginSuccess(fullUser);
|
|
249
157
|
onAuthStateChange?.(fullUser);
|
|
@@ -260,7 +168,6 @@ export const useAuthOperations = ({
|
|
|
260
168
|
setActiveSessionId,
|
|
261
169
|
switchSession,
|
|
262
170
|
updateSessions,
|
|
263
|
-
storage,
|
|
264
171
|
],
|
|
265
172
|
);
|
|
266
173
|
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
User,
|
|
8
8
|
UserPreferences,
|
|
9
9
|
} from '@oxyhq/core';
|
|
10
|
+
import type { UserProfileUpdate } from '@oxyhq/contracts';
|
|
10
11
|
import {
|
|
11
12
|
queryKeys,
|
|
12
13
|
invalidateAccountQueries,
|
|
@@ -29,7 +30,7 @@ export const useUpdateProfile = () => {
|
|
|
29
30
|
|
|
30
31
|
return useMutation({
|
|
31
32
|
mutationKey: [...mutationKeys.account.updateProfile],
|
|
32
|
-
mutationFn: async (updates:
|
|
33
|
+
mutationFn: async (updates: UserProfileUpdate) => {
|
|
33
34
|
return authenticatedApiCall<User>(
|
|
34
35
|
oxyServices,
|
|
35
36
|
activeSessionId,
|
|
@@ -46,17 +47,18 @@ export const useUpdateProfile = () => {
|
|
|
46
47
|
|
|
47
48
|
// Optimistically update
|
|
48
49
|
if (previousUser) {
|
|
49
|
-
|
|
50
|
+
const optimisticUser: User = {
|
|
50
51
|
...previousUser,
|
|
51
52
|
...updates,
|
|
52
|
-
|
|
53
|
+
name: updates.name
|
|
54
|
+
? { ...previousUser.name, ...updates.name }
|
|
55
|
+
: previousUser.name,
|
|
56
|
+
};
|
|
57
|
+
queryClient.setQueryData<User>(queryKeys.accounts.current(), optimisticUser);
|
|
53
58
|
|
|
54
59
|
// Also update profile query if sessionId is available
|
|
55
60
|
if (activeSessionId) {
|
|
56
|
-
queryClient.setQueryData<User>(queryKeys.users.profile(activeSessionId),
|
|
57
|
-
...previousUser,
|
|
58
|
-
...updates,
|
|
59
|
-
});
|
|
61
|
+
queryClient.setQueryData<User>(queryKeys.users.profile(activeSessionId), optimisticUser);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -684,4 +686,3 @@ export const useUploadFile = () => {
|
|
|
684
686
|
},
|
|
685
687
|
});
|
|
686
688
|
};
|
|
687
|
-
|
|
@@ -252,19 +252,16 @@ export function useDeviceAccounts(): UseDeviceAccountsResult {
|
|
|
252
252
|
|
|
253
253
|
if (fromSharedApex) {
|
|
254
254
|
// Shared apex path: every entry carries a real per-account user.
|
|
255
|
-
built = sharedAccounts.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const accountUser: DeviceAccountUser = entry.user
|
|
260
|
-
id: '',
|
|
261
|
-
username: '',
|
|
262
|
-
};
|
|
255
|
+
built = sharedAccounts.flatMap((entry): DeviceAccount[] => {
|
|
256
|
+
if (!entry.user) {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
const accountUser: DeviceAccountUser = entry.user;
|
|
263
260
|
const displayName = getAccountDisplayName(accountUser, locale);
|
|
264
261
|
const handle = getAccountFallbackHandle(accountUser);
|
|
265
|
-
const email = entry.user
|
|
262
|
+
const email = entry.user.email ?? null;
|
|
266
263
|
const secondaryHandle = handle ? `@${handle}` : null;
|
|
267
|
-
return {
|
|
264
|
+
return [{
|
|
268
265
|
sessionId: entry.sessionId,
|
|
269
266
|
authuser: entry.authuser,
|
|
270
267
|
// Provisional; finalised by `markCurrentAccount` below so the
|
|
@@ -274,37 +271,36 @@ export function useDeviceAccounts(): UseDeviceAccountsResult {
|
|
|
274
271
|
// Real email, or null (NEVER synthesized). The UI uses the
|
|
275
272
|
// `@handle` line only when email is genuinely absent.
|
|
276
273
|
email: email ?? secondaryHandle,
|
|
277
|
-
avatarUrl: resolveAvatarUrl(entry.user
|
|
278
|
-
color: entry.user
|
|
274
|
+
avatarUrl: resolveAvatarUrl(entry.user.avatar),
|
|
275
|
+
color: entry.user.color ?? null,
|
|
279
276
|
user: accountUser,
|
|
280
|
-
};
|
|
277
|
+
}];
|
|
281
278
|
});
|
|
282
279
|
} else {
|
|
283
280
|
// Local fallback path: build from the SDK's multi-session store. The
|
|
284
281
|
// active session row gets the full loaded `user`; inactive fallback
|
|
285
282
|
// rows carry only what the `ClientSession` exposes (no synthesized
|
|
286
283
|
// identity — they show the active user's data only when active).
|
|
287
|
-
built = (sessions ?? []).
|
|
284
|
+
built = (sessions ?? []).flatMap((session: ClientSession): DeviceAccount[] => {
|
|
288
285
|
const isCurrent = session.sessionId === activeSessionId;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
286
|
+
if (!isCurrent || !user) {
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
const accountUser: DeviceAccountUser = user;
|
|
292
290
|
const displayName = getAccountDisplayName(accountUser, locale);
|
|
293
291
|
const handle = getAccountFallbackHandle(accountUser);
|
|
294
|
-
const email =
|
|
292
|
+
const email = user.email ?? null;
|
|
295
293
|
const secondaryHandle = handle ? `@${handle}` : null;
|
|
296
|
-
|
|
297
|
-
const color = isCurrent && user?.color ? user.color : null;
|
|
298
|
-
return {
|
|
294
|
+
return [{
|
|
299
295
|
sessionId: session.sessionId,
|
|
300
296
|
authuser: session.authuser,
|
|
301
297
|
isCurrent,
|
|
302
298
|
displayName,
|
|
303
299
|
email: email ?? secondaryHandle,
|
|
304
|
-
avatarUrl: resolveAvatarUrl(avatar),
|
|
305
|
-
color,
|
|
300
|
+
avatarUrl: resolveAvatarUrl(user.avatar),
|
|
301
|
+
color: user.color ?? null,
|
|
306
302
|
user: accountUser,
|
|
307
|
-
};
|
|
303
|
+
}];
|
|
308
304
|
});
|
|
309
305
|
}
|
|
310
306
|
|
|
@@ -1,38 +1,51 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import { useI18n } from './useI18n';
|
|
3
2
|
import { useUpdateProfile } from './mutations/useAccountMutations';
|
|
4
3
|
import { useAuthStore } from '../stores/authStore';
|
|
4
|
+
import type { UserProfileUpdate } from '@oxyhq/contracts';
|
|
5
|
+
|
|
6
|
+
interface ProfileLocation {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
coordinates?: { lat: number; lon: number };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ProfileLinkMetadata {
|
|
14
|
+
url: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
image?: string;
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
5
20
|
|
|
6
21
|
export interface ProfileUpdateData {
|
|
7
|
-
|
|
22
|
+
firstName?: string;
|
|
8
23
|
lastName?: string;
|
|
9
24
|
username?: string;
|
|
10
25
|
email?: string;
|
|
11
26
|
bio?: string;
|
|
12
27
|
location?: string;
|
|
13
|
-
locations?:
|
|
14
|
-
id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
label?: string;
|
|
17
|
-
coordinates?: { lat: number; lon: number };
|
|
18
|
-
}>;
|
|
28
|
+
locations?: ProfileLocation[];
|
|
19
29
|
links?: string[];
|
|
20
|
-
linksMetadata?:
|
|
21
|
-
url: string;
|
|
22
|
-
title?: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
image?: string;
|
|
25
|
-
id: string;
|
|
26
|
-
}>;
|
|
30
|
+
linksMetadata?: ProfileLinkMetadata[];
|
|
27
31
|
avatar?: string;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
type ProfileFieldValue = string | ProfileLocation[] | ProfileLinkMetadata[];
|
|
35
|
+
|
|
36
|
+
function isProfileLocationArray(value: ProfileFieldValue): value is ProfileLocation[] {
|
|
37
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'object' && item !== null && 'name' in item);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isProfileLinkMetadataArray(value: ProfileFieldValue): value is ProfileLinkMetadata[] {
|
|
41
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'object' && item !== null && 'url' in item);
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
/**
|
|
31
45
|
* Hook for managing profile editing operations
|
|
32
46
|
* Provides functions to update profile fields and handle saving
|
|
33
47
|
*/
|
|
34
48
|
export const useProfileEditing = () => {
|
|
35
|
-
const { t } = useI18n();
|
|
36
49
|
const updateProfileMutation = useUpdateProfile();
|
|
37
50
|
|
|
38
51
|
/**
|
|
@@ -40,7 +53,7 @@ export const useProfileEditing = () => {
|
|
|
40
53
|
*/
|
|
41
54
|
const saveProfile = useCallback(async (updates: ProfileUpdateData) => {
|
|
42
55
|
// Prepare update object
|
|
43
|
-
const updateData:
|
|
56
|
+
const updateData: UserProfileUpdate = {};
|
|
44
57
|
|
|
45
58
|
if (updates.username !== undefined) {
|
|
46
59
|
updateData.username = updates.username;
|
|
@@ -70,11 +83,11 @@ export const useProfileEditing = () => {
|
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
// Handle name field
|
|
73
|
-
if (updates.
|
|
86
|
+
if (updates.firstName !== undefined || updates.lastName !== undefined) {
|
|
74
87
|
const currentUser = useAuthStore.getState().user;
|
|
75
88
|
const currentName = currentUser?.name;
|
|
76
89
|
updateData.name = {
|
|
77
|
-
first: updates.
|
|
90
|
+
first: updates.firstName ?? (typeof currentName === 'object' ? currentName?.first : '') ?? '',
|
|
78
91
|
last: updates.lastName ?? (typeof currentName === 'object' ? currentName?.last : '') ?? '',
|
|
79
92
|
};
|
|
80
93
|
}
|
|
@@ -86,33 +99,39 @@ export const useProfileEditing = () => {
|
|
|
86
99
|
// Error toast is handled by the mutation
|
|
87
100
|
return false;
|
|
88
101
|
}
|
|
89
|
-
}, [updateProfileMutation
|
|
102
|
+
}, [updateProfileMutation]);
|
|
90
103
|
|
|
91
104
|
/**
|
|
92
105
|
* Update a single profile field
|
|
93
106
|
*/
|
|
94
|
-
const updateField = useCallback(async (field: string, value:
|
|
107
|
+
const updateField = useCallback(async (field: string, value: ProfileFieldValue) => {
|
|
95
108
|
const updates: ProfileUpdateData = {};
|
|
96
109
|
|
|
97
110
|
switch (field) {
|
|
98
|
-
case '
|
|
99
|
-
|
|
111
|
+
case 'firstName':
|
|
112
|
+
if (typeof value !== 'string') return false;
|
|
113
|
+
updates.firstName = value;
|
|
100
114
|
break;
|
|
101
115
|
case 'username':
|
|
116
|
+
if (typeof value !== 'string') return false;
|
|
102
117
|
updates.username = value;
|
|
103
118
|
break;
|
|
104
119
|
case 'email':
|
|
120
|
+
if (typeof value !== 'string') return false;
|
|
105
121
|
updates.email = value;
|
|
106
122
|
break;
|
|
107
123
|
case 'bio':
|
|
124
|
+
if (typeof value !== 'string') return false;
|
|
108
125
|
updates.bio = value;
|
|
109
126
|
break;
|
|
110
127
|
case 'location':
|
|
128
|
+
if (!isProfileLocationArray(value)) return false;
|
|
111
129
|
updates.locations = value;
|
|
112
130
|
break;
|
|
113
131
|
case 'links':
|
|
132
|
+
if (!isProfileLinkMetadataArray(value)) return false;
|
|
114
133
|
updates.linksMetadata = value;
|
|
115
|
-
updates.links = value.map((link
|
|
134
|
+
updates.links = value.map((link) => link.url);
|
|
116
135
|
break;
|
|
117
136
|
default:
|
|
118
137
|
return false;
|
|
@@ -129,9 +148,3 @@ export const useProfileEditing = () => {
|
|
|
129
148
|
};
|
|
130
149
|
|
|
131
150
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
@@ -20,7 +20,7 @@ import { SettingsIcon } from '../components/SettingsIcon';
|
|
|
20
20
|
import { useTheme } from '@oxyhq/bloom/theme';
|
|
21
21
|
import { useColorScheme } from '../hooks/useColorScheme';
|
|
22
22
|
import { Colors } from '../constants/theme';
|
|
23
|
-
import { normalizeColorScheme } from '
|
|
23
|
+
import { normalizeColorScheme } from '@oxyhq/core';
|
|
24
24
|
import { useOxy } from '../context/OxyContext';
|
|
25
25
|
import { useI18n } from '../hooks/useI18n';
|
|
26
26
|
import { SettingsListGroup, SettingsListItem } from '@oxyhq/bloom/settings-list';
|
|
@@ -93,6 +93,7 @@ const ZOOM_CHIP_FADE_DURATION_MS = 200;
|
|
|
93
93
|
const CANVAS_BG = '#000000';
|
|
94
94
|
const RING_COLOR = '#ffffff';
|
|
95
95
|
const RING_WIDTH = 2;
|
|
96
|
+
const REMOTE_HTTP_URI_PATTERN = /^https?:\/\//i;
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
99
|
* Clamp the translation so the image edges never leave the viewport at any
|
|
@@ -154,6 +155,64 @@ async function loadImageManipulator(): Promise<ImageManipulatorModule> {
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
interface PreparedManipulatorImage {
|
|
159
|
+
uri: string;
|
|
160
|
+
cleanup?: () => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isCanvasLoadFailure(err: unknown): boolean {
|
|
164
|
+
return (
|
|
165
|
+
Platform.OS === 'web' &&
|
|
166
|
+
typeof HTMLCanvasElement !== 'undefined' &&
|
|
167
|
+
err instanceof HTMLCanvasElement
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function normalizeCropError(err: unknown): Error {
|
|
172
|
+
if (err instanceof Error) return err;
|
|
173
|
+
if (isCanvasLoadFailure(err)) {
|
|
174
|
+
return new Error('Image could not be loaded for cropping');
|
|
175
|
+
}
|
|
176
|
+
if (typeof err === 'string' && err.trim()) {
|
|
177
|
+
return new Error(err.trim());
|
|
178
|
+
}
|
|
179
|
+
return new Error('Failed to crop image');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function prepareImageForManipulator(uri: string): Promise<PreparedManipulatorImage> {
|
|
183
|
+
if (Platform.OS !== 'web' || !REMOTE_HTTP_URI_PATTERN.test(uri)) {
|
|
184
|
+
return { uri };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let response: Response;
|
|
188
|
+
try {
|
|
189
|
+
response = await fetch(uri);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
192
|
+
throw new Error(`Image could not be loaded for cropping: ${message}`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!response.ok) {
|
|
196
|
+
throw new Error(`Image could not be loaded for cropping (${response.status})`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const blob = await response.blob();
|
|
200
|
+
if (blob.size <= 0) {
|
|
201
|
+
throw new Error('Image could not be loaded for cropping');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const contentType = response.headers.get('content-type') || blob.type;
|
|
205
|
+
if (contentType && !contentType.toLowerCase().startsWith('image/')) {
|
|
206
|
+
throw new Error('Selected file is not an image');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
210
|
+
return {
|
|
211
|
+
uri: objectUrl,
|
|
212
|
+
cleanup: () => URL.revokeObjectURL(objectUrl),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
157
216
|
/**
|
|
158
217
|
* Haptic feedback wrapper. `expo-haptics` is an optional dependency — when not
|
|
159
218
|
* installed (or on web), all calls degrade silently. We resolve the module once
|
|
@@ -622,6 +681,7 @@ const AvatarCropScreen: React.FC<AvatarCropScreenProps> = ({
|
|
|
622
681
|
}
|
|
623
682
|
|
|
624
683
|
setIsProcessing(true);
|
|
684
|
+
let preparedImageCleanup: (() => void) | undefined;
|
|
625
685
|
try {
|
|
626
686
|
const { manipulateAsync, SaveFormat } = await loadImageManipulator();
|
|
627
687
|
|
|
@@ -665,8 +725,10 @@ const AvatarCropScreen: React.FC<AvatarCropScreenProps> = ({
|
|
|
665
725
|
},
|
|
666
726
|
);
|
|
667
727
|
|
|
728
|
+
const preparedImage = await prepareImageForManipulator(imageUri);
|
|
729
|
+
preparedImageCleanup = preparedImage.cleanup;
|
|
668
730
|
const result = await manipulateAsync(
|
|
669
|
-
|
|
731
|
+
preparedImage.uri,
|
|
670
732
|
[
|
|
671
733
|
{
|
|
672
734
|
crop: {
|
|
@@ -701,13 +763,14 @@ const AvatarCropScreen: React.FC<AvatarCropScreenProps> = ({
|
|
|
701
763
|
// success toast (uploads typically toast their own outcome).
|
|
702
764
|
onClose?.();
|
|
703
765
|
} catch (err) {
|
|
704
|
-
|
|
705
|
-
|
|
766
|
+
const normalizedError = normalizeCropError(err);
|
|
767
|
+
logger.error('handleConfirm failed', normalizedError, { component: LOG_COMPONENT });
|
|
706
768
|
void hapticNotification('error');
|
|
707
769
|
toast.error(
|
|
708
|
-
message || t('editProfile.toasts.cropFailed') || 'Failed to crop image',
|
|
770
|
+
normalizedError.message || t('editProfile.toasts.cropFailed') || 'Failed to crop image',
|
|
709
771
|
);
|
|
710
772
|
} finally {
|
|
773
|
+
preparedImageCleanup?.();
|
|
711
774
|
setIsProcessing(false);
|
|
712
775
|
}
|
|
713
776
|
}, [baseFit, imageUri, naturalSize, onClose, onConfirm, t]);
|
|
@@ -15,7 +15,7 @@ import { useAuthorizedApps } from '../hooks/queries/useAccountQueries';
|
|
|
15
15
|
import { useRevokeAuthorizedApp } from '../hooks/mutations/useAccountMutations';
|
|
16
16
|
import { useColorScheme } from '../hooks/useColorScheme';
|
|
17
17
|
import { Colors } from '../constants/theme';
|
|
18
|
-
import { normalizeColorScheme, normalizeTheme } from '
|
|
18
|
+
import { normalizeColorScheme, normalizeTheme } from '@oxyhq/core';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Format an ISO-8601 timestamp as a human-readable relative time. Mirrors the
|