diff --git a/Gotrue/Api.cs b/Gotrue/Api.cs index a971eca..33adf17 100644 --- a/Gotrue/Api.cs +++ b/Gotrue/Api.cs @@ -89,10 +89,19 @@ public Task SignInWithEmail(string email, string password) /// Sends a magic login link to an email address. /// /// + /// /// - public Task SendMagicLinkEmail(string email) + public Task SendMagicLinkEmail(string email, SignInOptions options = null) { var data = new Dictionary { { "email", email } }; + if (options != null) + { + if (!string.IsNullOrEmpty(options.RedirectTo)) + { + data.Add("redirect_to", options.RedirectTo); + } + } + return Helpers.MakeRequest(HttpMethod.Post, $"{Url}/magiclink", data, Headers); } @@ -377,16 +386,22 @@ public Task RefreshAccessToken(string refreshToken) /// /// Options used for signing up a user. /// - public class SignUpOptions + public class SignUpOptions : SignInOptions { /// - /// A URL or mobile address to send the user to after they are confirmed. + /// Optional user metadata. /// - public string RedirectTo { get; set; } + public Dictionary Data { get; set; } + } + // + /// Options used for signing in a user. + /// + public class SignInOptions + { /// - /// Optional user metadata. + /// A URL or mobile address to send the user to after they are confirmed. /// - public Dictionary Data { get; set; } + public string RedirectTo { get; set; } } } diff --git a/Gotrue/Client.cs b/Gotrue/Client.cs index ab1f68e..5328bc2 100644 --- a/Gotrue/Client.cs +++ b/Gotrue/Client.cs @@ -258,14 +258,15 @@ public async Task SignUp(SignUpType type, string identifier, string pas /// Sends a Magic email login link to the specified email. /// /// + /// /// - public async Task SignIn(string email) + public async Task SignIn(string email, SignInOptions options = null) { await DestroySession(); try { - await api.SendMagicLinkEmail(email); + await api.SendMagicLinkEmail(email, options); return true; } catch (RequestException ex) diff --git a/Gotrue/StatelessClient.cs b/Gotrue/StatelessClient.cs index 7929e17..f9ad6b9 100644 --- a/Gotrue/StatelessClient.cs +++ b/Gotrue/StatelessClient.cs @@ -75,12 +75,14 @@ public static async Task SignUp(SignUpType type, string identifier, str /// Sends a Magic email login link to the specified email. /// /// + /// + /// /// - public static async Task SignIn(string email, StatelessClientOptions options) + public static async Task SignIn(string email, StatelessClientOptions options, SignInOptions signInOptions = null) { try { - await GetApi(options).SendMagicLinkEmail(email); + await GetApi(options).SendMagicLinkEmail(email, signInOptions); return true; } catch (RequestException ex) diff --git a/GotrueTests/StatelessClient.cs b/GotrueTests/StatelessClient.cs index e638a63..ae6cd37 100644 --- a/GotrueTests/StatelessClient.cs +++ b/GotrueTests/StatelessClient.cs @@ -154,21 +154,29 @@ public async Task SignsOut() [TestMethod("StatelessClient: Sends Magic Login Email")] public async Task SendsMagicLoginEmail() { - var user = $"{RandomString(12)}@supabase.io"; - await SignUp(user, password, options); + var user1 = $"{RandomString(12)}@supabase.io"; + await SignUp(user1, password, options); - var result = await SignIn(user, options); - Assert.IsTrue(result); + var result1 = await SignIn(user1, options); + Assert.IsTrue(result1); + + var user2 = $"{RandomString(12)}@supabase.io"; + var result2 = await SignIn(user2, options, new SignInOptions { RedirectTo = $"com.{RandomString(12)}.deeplink://login" }); + Assert.IsTrue(result2); } [TestMethod("StatelessClient: Sends Magic Login Email (Alias)")] public async Task SendsMagicLoginEmailAlias() { - var user = $"{RandomString(12)}@supabase.io"; - await SignUp(user, password, options); + var user1 = $"{RandomString(12)}@supabase.io"; + await SignUp(user1, password, options); - var result = await SendMagicLink(user, options); - Assert.IsTrue(result); + var result1 = await SignIn(user1, options); + Assert.IsTrue(result1); + + var user2 = $"{RandomString(12)}@supabase.io"; + var result2 = await SignIn(user2, options, new SignInOptions { RedirectTo = $"com.{RandomString(12)}.deeplink://login" }); + Assert.IsTrue(result2); } [TestMethod("StatelessClient: Returns Auth Url for Provider")]