Skip to content

Commit c113bd8

Browse files
committed
wip
1 parent 0d8d45a commit c113bd8

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

packages/react/src/hooks/useSignIn.ts

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,50 @@ const createStoreObservable = (signInResource: SignInResource) => {
7575
const wrapSignInWithObservable = (signIn: SignInResource): ObservableSignInResource => {
7676
const observable = createStoreObservable(signIn);
7777

78-
return new Proxy(signIn, {
78+
// Create a new object that extends the signIn resource with the observable method
79+
const wrappedSignIn = Object.create(signIn);
80+
81+
// Add the observable method directly to the object
82+
Object.defineProperty(wrappedSignIn, 'observable', {
83+
value: observable,
84+
writable: false,
85+
enumerable: true,
86+
configurable: false
87+
});
88+
89+
// Also use a Proxy to ensure all other properties are properly forwarded
90+
return new Proxy(wrappedSignIn, {
7991
get(target, prop) {
8092
if (prop === 'observable') {
8193
return observable;
8294
}
83-
return (target as any)[prop];
95+
// Forward to the original signIn object for all other properties
96+
return (target)[prop] ?? (signIn as any)[prop];
8497
},
8598
has(target, prop) {
8699
if (prop === 'observable') {
87100
return true;
88101
}
89-
return prop in target;
102+
return prop in target || prop in signIn;
103+
},
104+
ownKeys(target) {
105+
// Include 'observable' in the list of own keys
106+
const keys = [...Object.getOwnPropertyNames(target), ...Object.getOwnPropertyNames(signIn)];
107+
if (!keys.includes('observable')) {
108+
keys.push('observable');
109+
}
110+
return keys;
111+
},
112+
getOwnPropertyDescriptor(target, prop) {
113+
if (prop === 'observable') {
114+
return {
115+
value: observable,
116+
writable: false,
117+
enumerable: true,
118+
configurable: false
119+
};
120+
}
121+
return Object.getOwnPropertyDescriptor(target, prop) || Object.getOwnPropertyDescriptor(signIn, prop);
90122
}
91123
}) as ObservableSignInResource;
92124
};
@@ -134,8 +166,10 @@ export const useSignIn = () => {
134166
}
135167

136168
const createProxy = <T>(target: 'signIn' | 'setActive'): T => {
169+
const proxyTarget = target === 'signIn' ? { observable: () => ({}) } : {};
170+
137171
return new Proxy(
138-
{},
172+
proxyTarget,
139173
{
140174
get(_, prop) {
141175
// Handle the observable property for the proxy as well
@@ -186,6 +220,24 @@ export const useSignIn = () => {
186220
// Return true for all other properties to indicate they exist on the proxy
187221
return true;
188222
},
223+
ownKeys(_) {
224+
// For signIn proxy, include 'observable' in enumerable keys
225+
if (target === 'signIn') {
226+
return ['observable'];
227+
}
228+
return [];
229+
},
230+
getOwnPropertyDescriptor(_, prop) {
231+
if (prop === 'observable' && target === 'signIn') {
232+
return {
233+
value: () => ({}),
234+
writable: false,
235+
enumerable: true,
236+
configurable: false
237+
};
238+
}
239+
return undefined;
240+
}
189241
},
190242
) as T;
191243
};

0 commit comments

Comments
 (0)