@@ -4,19 +4,19 @@ use std::env;
4
4
5
5
use reqwest:: {
6
6
header:: { self , HeaderMap , HeaderValue , AUTHORIZATION , CONTENT_TYPE } ,
7
- Client , Response , Url ,
7
+ Client , Url ,
8
8
} ;
9
- use serde_json:: from_str;
9
+ use serde_json:: { from_str, Value } ;
10
10
11
11
use crate :: {
12
12
error:: Error :: { self , AuthError } ,
13
13
models:: {
14
- AuthClient , AuthServerHealth , AuthServerSettings , IdTokenCredentials , LogoutScope ,
15
- OAuthResponse , OTPResponse , Provider , RefreshSessionPayload , RequestMagicLinkPayload ,
16
- ResendParams , ResetPasswordForEmailPayload , SendSMSOtpPayload , Session ,
17
- SignInEmailOtpParams , SignInWithEmailAndPasswordPayload , SignInWithEmailOtpPayload ,
18
- SignInWithOAuthOptions , SignInWithPhoneAndPasswordPayload , SignInWithSSO ,
19
- SignUpWithEmailAndPasswordPayload , SignUpWithPasswordOptions ,
14
+ AuthClient , AuthServerHealth , AuthServerSettings , IdTokenCredentials , InviteParams ,
15
+ LogoutScope , OAuthResponse , OTPResponse , Provider , RefreshSessionPayload ,
16
+ RequestMagicLinkPayload , ResendParams , ResetPasswordForEmailPayload , SendSMSOtpPayload ,
17
+ Session , SignInEmailOtpParams , SignInWithEmailAndPasswordPayload ,
18
+ SignInWithEmailOtpPayload , SignInWithOAuthOptions , SignInWithPhoneAndPasswordPayload ,
19
+ SignInWithSSO , SignUpWithEmailAndPasswordPayload , SignUpWithPasswordOptions ,
20
20
SignUpWithPhoneAndPasswordPayload , UpdateUserPayload , User , VerifyOtpParams , AUTH_V1 ,
21
21
} ,
22
22
} ;
@@ -555,14 +555,27 @@ impl AuthClient {
555
555
Ok ( session)
556
556
}
557
557
558
- // TODO: Add test
559
558
/// Sends an invite link to an email address.
560
- pub async fn invite_user_by_email < S : Into < String > > ( & self , email : S ) -> Result < User , Error > {
559
+ pub async fn invite_user_by_email < S : Into < String > > (
560
+ & self ,
561
+ email : S ,
562
+ data : Option < Value > ,
563
+ bearer_token : S ,
564
+ ) -> Result < User , Error > {
561
565
let mut headers = HeaderMap :: new ( ) ;
562
566
headers. insert ( "apikey" , HeaderValue :: from_str ( & self . api_key ) ?) ;
563
567
headers. insert ( CONTENT_TYPE , HeaderValue :: from_str ( "application/json" ) ?) ;
568
+ headers. insert (
569
+ AUTHORIZATION ,
570
+ HeaderValue :: from_str ( & format ! ( "Bearer {}" , & bearer_token. into( ) ) ) ?,
571
+ ) ;
572
+
573
+ let invite_payload = InviteParams {
574
+ email : email. into ( ) ,
575
+ data,
576
+ } ;
564
577
565
- let body = serde_json:: to_string ( & email . into ( ) ) ?;
578
+ let body = serde_json:: to_string ( & invite_payload ) ?;
566
579
567
580
let response = self
568
581
. client
0 commit comments