@@ -36,7 +36,14 @@ function getHeader(
36
36
return header ?? null ;
37
37
}
38
38
39
- export const context = async < IUser extends User = User , Ctx extends object = object > (
39
+ export const context = async <
40
+ IUserOrContext extends object = User ,
41
+ Ctx extends object = object ,
42
+ _User_ extends User = IUserOrContext extends User ? IUserOrContext : User ,
43
+ _Context_ extends object = IUserOrContext extends User
44
+ ? IContext < IUserOrContext >
45
+ : IUserOrContext ,
46
+ > (
40
47
{
41
48
req,
42
49
request,
@@ -51,8 +58,8 @@ export const context = async <IUser extends User = User, Ctx extends object = ob
51
58
} ,
52
59
{ createOperationController, ctx, ...options } : AccountsContextOptions < Ctx >
53
60
) : AccountsContextOptions < Ctx > extends { ctx : any }
54
- ? Promise < IContext < IUser > & Ctx >
55
- : Promise < IContext < IUser > > => {
61
+ ? Promise < _Context_ & Ctx >
62
+ : Promise < _Context_ > => {
56
63
const reqOrRequest = request ?? req ;
57
64
if ( ! reqOrRequest ) {
58
65
return {
@@ -63,7 +70,7 @@ export const context = async <IUser extends User = User, Ctx extends object = ob
63
70
userAgent : '' ,
64
71
} ,
65
72
...ctx ,
66
- } ;
73
+ } satisfies IContext < _User_ > as _Context_ ;
67
74
}
68
75
69
76
const headerName = options . headerName || 'Authorization' ;
@@ -81,7 +88,7 @@ export const context = async <IUser extends User = User, Ctx extends object = ob
81
88
} ) ;
82
89
try {
83
90
user = await controller . injector
84
- . get < AccountsServer < IUser > > ( AccountsServer )
91
+ . get < AccountsServer < _User_ > > ( AccountsServer )
85
92
. resumeSession ( authToken ) ;
86
93
} catch ( error ) {
87
94
// Empty catch
@@ -112,5 +119,5 @@ export const context = async <IUser extends User = User, Ctx extends object = ob
112
119
ip,
113
120
} ,
114
121
...ctx ,
115
- } ;
122
+ } satisfies IContext < _User_ > as _Context_ ;
116
123
} ;
0 commit comments