@@ -14,7 +14,7 @@ use crate::{
14
14
AuthClient , AuthServerHealth , AuthServerSettings , IdTokenCredentials , InviteParams ,
15
15
LogoutScope , OAuthResponse , OTPResponse , Provider , RefreshSessionPayload ,
16
16
RequestMagicLinkPayload , ResendParams , ResetPasswordForEmailPayload , SendSMSOtpPayload ,
17
- Session , SignInEmailOtpParams , SignInWithEmailAndPasswordPayload ,
17
+ Session , SignInAnonymouslyPayload , SignInEmailOtpParams , SignInWithEmailAndPasswordPayload ,
18
18
SignInWithEmailOtpPayload , SignInWithOAuthOptions , SignInWithPhoneAndPasswordPayload ,
19
19
SignInWithSSO , SignUpWithEmailAndPasswordPayload , SignUpWithPasswordOptions ,
20
20
SignUpWithPhoneAndPasswordPayload , UpdatedUser , User , VerifyOtpParams , AUTH_V1 ,
@@ -237,6 +237,51 @@ impl AuthClient {
237
237
Ok ( session)
238
238
}
239
239
240
+ /// Sign in a new user anonymously. This actually signs up a user, but it's
241
+ /// called "sign in" by Supabase in their own client, so that's why it's
242
+ /// named like this here. You can also pass in the same signup options
243
+ /// that work for the other `sign_up_*` methods, but that's not required.
244
+ ///
245
+ /// # Example
246
+ /// ```
247
+ /// let session = auth_client
248
+ /// .sign_in_anonymously(demo_options)
249
+ /// .await
250
+ /// .unwrap();
251
+ ///
252
+ /// assert!(session.user.user_metadata.display_name == demo_options.data.display_name)
253
+ /// ```
254
+ pub async fn sign_in_anonymously (
255
+ & self ,
256
+ options : Option < SignUpWithPasswordOptions > ,
257
+ ) -> Result < Session , Error > {
258
+ let payload = SignInAnonymouslyPayload { options } ;
259
+
260
+ let mut headers = header:: HeaderMap :: new ( ) ;
261
+ headers. insert ( CONTENT_TYPE , HeaderValue :: from_str ( "application/json" ) ?) ;
262
+ headers. insert ( "apikey" , HeaderValue :: from_str ( & self . api_key ) ?) ;
263
+
264
+ let body = serde_json:: to_string ( & payload) ?;
265
+
266
+ let response = self
267
+ . client
268
+ . post ( format ! ( "{}{}/signup" , self . project_url, AUTH_V1 ) )
269
+ . headers ( headers)
270
+ . body ( body)
271
+ . send ( )
272
+ . await ?;
273
+
274
+ let res_status = response. status ( ) ;
275
+ let res_body = response. text ( ) . await ?;
276
+
277
+ let session: Session = from_str ( & res_body) . map_err ( |_| AuthError {
278
+ status : res_status,
279
+ message : res_body,
280
+ } ) ?;
281
+
282
+ Ok ( session)
283
+ }
284
+
240
285
/// Sends a login email containing a magic link
241
286
/// # Example
242
287
/// ```
0 commit comments