@@ -20,6 +20,13 @@ export type ClientWithSessionAndUserManagers<SessionGivenOptions, SessionSchemaT
20
20
user : { findMany : FindManyFunction < UserGivenOptions , any , UserSchemaT , any > } ;
21
21
} ;
22
22
23
+ export type ClientWithSessionAndMaybeUserManagers < SessionGivenOptions , SessionSchemaT , UserGivenOptions , UserSchemaT > = Omit <
24
+ ClientWithSessionAndUserManagers < SessionGivenOptions , SessionSchemaT , UserGivenOptions , UserSchemaT > ,
25
+ "user"
26
+ > & {
27
+ user ?: { findMany : FindManyFunction < UserGivenOptions , any , UserSchemaT , any > } ;
28
+ } ;
29
+
23
30
/**
24
31
* Used for fetching the current `Session` record from Gadget. Will suspend while the user is being fetched.
25
32
* @returns The current session
@@ -29,7 +36,7 @@ export function useSession<
29
36
SessionSchemaT ,
30
37
UserGivenOptions extends OptionsType ,
31
38
UserSchemaT ,
32
- Client extends ClientWithSessionAndUserManagers < SessionGivenOptions , SessionSchemaT , UserGivenOptions , UserSchemaT > ,
39
+ Client extends ClientWithSessionAndMaybeUserManagers < SessionGivenOptions , SessionSchemaT , UserGivenOptions , UserSchemaT > ,
33
40
Options extends Client [ "currentSession" ] [ "get" ] [ "optionsType" ] & ReadOperationOptions ,
34
41
ClientType extends Client | undefined
35
42
> (
@@ -44,7 +51,9 @@ export function useSession<
44
51
Exclude < ClientType , undefined > [ "currentSession" ] [ "get" ] [ "selectionType" ] ,
45
52
Options ,
46
53
Exclude < ClientType , undefined > [ "currentSession" ] [ "get" ] [ "defaultSelection" ] & {
47
- user : Exclude < ClientType , undefined > [ "user" ] [ "findMany" ] [ "defaultSelection" ] ;
54
+ user : Exclude < ClientType , undefined > [ "user" ] extends { findMany : FindManyFunction < UserGivenOptions , any , UserSchemaT , any > }
55
+ ? Exclude < ClientType , undefined > [ "user" ] [ "findMany" ] [ "defaultSelection" ]
56
+ : never ;
48
57
}
49
58
>
50
59
>
0 commit comments