@@ -10,7 +10,13 @@ import { getWithHooks } from "./with-hooks";
10
10
import { getIp } from "../utils/get-request-ip" ;
11
11
import { safeJSONParse } from "../utils/json" ;
12
12
import { generateId } from "../utils" ;
13
- import type { Adapter , AuthContext , BetterAuthOptions , Where } from "../types" ;
13
+ import type {
14
+ Adapter ,
15
+ AuthContext ,
16
+ BetterAuthOptions ,
17
+ GenericEndpointContext ,
18
+ Where ,
19
+ } from "../types" ;
14
20
15
21
export const createInternalAdapter = (
16
22
adapter : Adapter ,
@@ -31,6 +37,7 @@ export const createInternalAdapter = (
31
37
user : Omit < User , "id" | "createdAt" | "updatedAt" > & Partial < User > ,
32
38
account : Omit < Account , "userId" | "id" | "createdAt" | "updatedAt" > &
33
39
Partial < Account > ,
40
+ context ?: GenericEndpointContext ,
34
41
) => {
35
42
const createdUser = await createWithHooks (
36
43
{
@@ -39,6 +46,8 @@ export const createInternalAdapter = (
39
46
...user ,
40
47
} ,
41
48
"user" ,
49
+ undefined ,
50
+ context ,
42
51
) ;
43
52
const createdAccount = await createWithHooks (
44
53
{
@@ -48,6 +57,8 @@ export const createInternalAdapter = (
48
57
updatedAt : new Date ( ) ,
49
58
} ,
50
59
"account" ,
60
+ undefined ,
61
+ context ,
51
62
) ;
52
63
return {
53
64
user : createdUser ,
@@ -58,6 +69,7 @@ export const createInternalAdapter = (
58
69
user : Omit < User , "id" | "createdAt" | "updatedAt" | "emailVerified" > &
59
70
Partial < User > &
60
71
Record < string , any > ,
72
+ context ?: GenericEndpointContext ,
61
73
) => {
62
74
const createdUser = await createWithHooks (
63
75
{
@@ -68,13 +80,16 @@ export const createInternalAdapter = (
68
80
email : user . email . toLowerCase ( ) ,
69
81
} ,
70
82
"user" ,
83
+ undefined ,
84
+ context ,
71
85
) ;
72
86
return createdUser as T & User ;
73
87
} ,
74
88
createAccount : async < T > (
75
89
account : Omit < Account , "id" | "createdAt" | "updatedAt" > &
76
90
Partial < Account > &
77
91
Record < string , any > ,
92
+ context ?: GenericEndpointContext ,
78
93
) => {
79
94
const createdAccount = await createWithHooks (
80
95
{
@@ -83,6 +98,8 @@ export const createInternalAdapter = (
83
98
...account ,
84
99
} ,
85
100
"account" ,
101
+ undefined ,
102
+ context ,
86
103
) ;
87
104
return createdAccount as T & Account ;
88
105
} ,
@@ -190,6 +207,7 @@ export const createInternalAdapter = (
190
207
request : Request | Headers | undefined ,
191
208
dontRememberMe ?: boolean ,
192
209
override ?: Partial < Session > & Record < string , any > ,
210
+ context ?: GenericEndpointContext ,
193
211
) => {
194
212
const headers = request instanceof Request ? request . headers : request ;
195
213
const { id : _ , ...rest } = override || { } ;
@@ -248,6 +266,7 @@ export const createInternalAdapter = (
248
266
executeMainFn : options . session ?. storeSessionInDatabase ,
249
267
}
250
268
: undefined ,
269
+ context ,
251
270
) ;
252
271
return res as Session ;
253
272
} ,
@@ -384,6 +403,7 @@ export const createInternalAdapter = (
384
403
updateSession : async (
385
404
sessionToken : string ,
386
405
session : Partial < Session > & Record < string , any > ,
406
+ context ?: GenericEndpointContext ,
387
407
) => {
388
408
const updatedSession = await updateWithHooks < Session > (
389
409
session ,
@@ -411,6 +431,7 @@ export const createInternalAdapter = (
411
431
executeMainFn : options . session ?. storeSessionInDatabase ,
412
432
}
413
433
: undefined ,
434
+ context ,
414
435
) ;
415
436
return updatedSession ;
416
437
} ,
@@ -615,6 +636,7 @@ export const createInternalAdapter = (
615
636
linkAccount : async (
616
637
account : Omit < Account , "id" | "createdAt" | "updatedAt" > &
617
638
Partial < Account > ,
639
+ context ?: GenericEndpointContext ,
618
640
) => {
619
641
const _account = await createWithHooks (
620
642
{
@@ -623,12 +645,15 @@ export const createInternalAdapter = (
623
645
updatedAt : new Date ( ) ,
624
646
} ,
625
647
"account" ,
648
+ undefined ,
649
+ context ,
626
650
) ;
627
651
return _account ;
628
652
} ,
629
653
updateUser : async (
630
654
userId : string ,
631
655
data : Partial < User > & Record < string , any > ,
656
+ context ?: GenericEndpointContext ,
632
657
) => {
633
658
const user = await updateWithHooks < User > (
634
659
data ,
@@ -639,12 +664,15 @@ export const createInternalAdapter = (
639
664
} ,
640
665
] ,
641
666
"user" ,
667
+ undefined ,
668
+ context ,
642
669
) ;
643
670
return user ;
644
671
} ,
645
672
updateUserByEmail : async (
646
673
email : string ,
647
674
data : Partial < User & Record < string , any > > ,
675
+ context ?: GenericEndpointContext ,
648
676
) => {
649
677
const user = await updateWithHooks < User > (
650
678
data ,
@@ -655,10 +683,12 @@ export const createInternalAdapter = (
655
683
} ,
656
684
] ,
657
685
"user" ,
686
+ undefined ,
687
+ context ,
658
688
) ;
659
689
return user ;
660
690
} ,
661
- updatePassword : async ( userId : string , password : string ) => {
691
+ updatePassword : async ( userId : string , password : string , context ?: GenericEndpointContext , ) => {
662
692
await updateManyWithHooks (
663
693
{
664
694
password,
@@ -674,6 +704,8 @@ export const createInternalAdapter = (
674
704
} ,
675
705
] ,
676
706
"account" ,
707
+ undefined ,
708
+ context
677
709
) ;
678
710
} ,
679
711
findAccounts : async ( userId : string ) => {
@@ -712,17 +744,24 @@ export const createInternalAdapter = (
712
744
} ) ;
713
745
return account ;
714
746
} ,
715
- updateAccount : async ( accountId : string , data : Partial < Account > ) => {
747
+ updateAccount : async (
748
+ accountId : string ,
749
+ data : Partial < Account > ,
750
+ context ?: GenericEndpointContext ,
751
+ ) => {
716
752
const account = await updateWithHooks < Account > (
717
753
data ,
718
754
[ { field : "id" , value : accountId } ] ,
719
755
"account" ,
756
+ undefined ,
757
+ context ,
720
758
) ;
721
759
return account ;
722
760
} ,
723
761
createVerificationValue : async (
724
762
data : Omit < Verification , "createdAt" | "id" | "updatedAt" > &
725
763
Partial < Verification > ,
764
+ context ?: GenericEndpointContext ,
726
765
) => {
727
766
const verification = await createWithHooks (
728
767
{
@@ -731,6 +770,8 @@ export const createInternalAdapter = (
731
770
...data ,
732
771
} ,
733
772
"verification" ,
773
+ undefined ,
774
+ context ,
734
775
) ;
735
776
return verification as Verification ;
736
777
} ,
@@ -789,11 +830,14 @@ export const createInternalAdapter = (
789
830
updateVerificationValue : async (
790
831
id : string ,
791
832
data : Partial < Verification > ,
833
+ context ?: GenericEndpointContext ,
792
834
) => {
793
835
const verification = await updateWithHooks < Verification > (
794
836
data ,
795
837
[ { field : "id" , value : id } ] ,
796
838
"verification" ,
839
+ undefined ,
840
+ context ,
797
841
) ;
798
842
return verification ;
799
843
} ,
0 commit comments