Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Net;
using System.Threading.Tasks;
using Gotrue.Tests.Support;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Supabase.Gotrue.Resend;
using static Gotrue.Tests.TestUtils;

namespace Gotrue.Tests.Authentication;

[TestClass]
[TestCategory("E2E")]
public class ResendParametersTests : AuthClientFixture
{
[TestMethod]
public async Task Resend_ShouldRequestConfirmationCode_GivenSignUpType()
{
var email = RandomEmail();
var resend = new ResendParameters(ResendType.SignUp) { Email = email };
var response = await this.Client.Resend(resend);

Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.OK, response?.ResponseMessage?.StatusCode);
}

[TestMethod]
public async Task Resend_ShouldRequestConfirmationCode_GivenSmsType()
{
var resend = new ResendParameters(ResendType.Sms) { Phone = "5544989899898" };
var response = await this.Client.Resend(resend);

Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.OK, response?.ResponseMessage?.StatusCode);
}

[TestMethod]
public async Task Resend_ShouldRequestConfirmationCode_GivenPhoneChangeType()
{
var resend = new ResendParameters(ResendType.PhoneChange) { Phone = "5544989899898" };
var response = await this.Client.Resend(resend);

Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.OK, response?.ResponseMessage?.StatusCode);
}

[TestMethod]
public async Task Resend_ShouldRequestConfirmationCode_GivenEmailChangeType()
{
var resend = new ResendParameters(ResendType.EmailChange) { Email = RandomEmail() };
var response = await this.Client.Resend(resend);

Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.OK, response?.ResponseMessage?.StatusCode);
}
}
13 changes: 13 additions & 0 deletions packages/Gotrue/Gotrue/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Supabase.Gotrue.Exceptions;
using Supabase.Gotrue.Interfaces;
using Supabase.Gotrue.Mfa;
using Supabase.Gotrue.Resend;
using Supabase.Gotrue.Responses;
using static Supabase.Gotrue.Constants;

Expand Down Expand Up @@ -843,4 +844,16 @@ public Task<BaseResponse> GenerateLink(string jwt, GenerateLinkOptions options)

return this.MakeRequestAsync<Session>(HttpMethod.Post, $"{this.Url}/token?grant_type=refresh_token", data, this.Headers.MergeLeft(headers));
}

/// <summary>
/// Resends a confirmation code to a user's email or phone.
/// </summary>
/// <param name="resendParameters"></param>
/// <returns>BaseResponse</returns>
public Task<BaseResponse> Resend(ResendParameters resendParameters) => this.MakeRequestAsync(
HttpMethod.Post,
$"{this.Url}/resend",
resendParameters,
this.Headers
);
}
5 changes: 5 additions & 0 deletions packages/Gotrue/Gotrue/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Supabase.Gotrue.Exceptions;
using Supabase.Gotrue.Interfaces;
using Supabase.Gotrue.Mfa;
using Supabase.Gotrue.Resend;
using Supabase.Gotrue.Responses;
using static Supabase.Gotrue.Constants;
using static Supabase.Gotrue.Constants.AuthState;
using static Supabase.Gotrue.Exceptions.FailureHint.Reason;
Expand Down Expand Up @@ -947,6 +949,9 @@ private void ApplyLoadedSession(Session? before, Session? loaded)
/// <inheritdoc />
public void Shutdown() => this.NotifyAuthStateChange(AuthState.Shutdown);

/// <inheritdoc />
public Task<BaseResponse> Resend(ResendParameters resendParameters) => this.api.Resend(resendParameters);

/// <inheritdoc />
public async Task<MfaEnrollResponse?> Enroll(MfaEnrollParams mfaEnrollParams)
{
Expand Down
Loading