C
C#7d ago
Catto

[ADVANCED] How to reset supabase auth password from ASP.NET WEB API SERVER?

aaaaaaaa
24 Replies
Catto
CattoOP7d ago
public async Task<ResetPasswordResponse> ResetPassword(ResetPasswordRequest request, string accessToken)
{

await supabaseClient.Auth.SetSession(accessToken, "", true);
var session = await supabaseClient.Auth.RefreshSession();
if (session == null || session.User == null)
{
return new ResetPasswordResponse
{
Status = ResetPasswordResult.Unauthorized,
Message = "Session or user doesn't exist, unauthorized",
};
}

var newUserAttributes = new UserAttributes
{
Password = request.Password
};

var user = await supabaseClient.Auth.Update(newUserAttributes);
if(user == null){
return new ResetPasswordResponse
{
Status = ResetPasswordResult.FailedToReset,
Message = "Failed to reset password, or failed to get user",
};
}

return new ResetPasswordResponse
{
Status = ResetPasswordResult.Success,
};
}
public async Task<ResetPasswordResponse> ResetPassword(ResetPasswordRequest request, string accessToken)
{

await supabaseClient.Auth.SetSession(accessToken, "", true);
var session = await supabaseClient.Auth.RefreshSession();
if (session == null || session.User == null)
{
return new ResetPasswordResponse
{
Status = ResetPasswordResult.Unauthorized,
Message = "Session or user doesn't exist, unauthorized",
};
}

var newUserAttributes = new UserAttributes
{
Password = request.Password
};

var user = await supabaseClient.Auth.Update(newUserAttributes);
if(user == null){
return new ResetPasswordResponse
{
Status = ResetPasswordResult.FailedToReset,
Message = "Failed to reset password, or failed to get user",
};
}

return new ResetPasswordResponse
{
Status = ResetPasswordResult.Success,
};
}
CODE IN THE SERVER
Catto
CattoOP7d ago
No description
Catto
CattoOP7d ago
heres the code in the NEXT JS FRONT END PROJECT the app/client so basically, the website sends a fetch request to that endppoint on my server to reset password and it passes the access token and so i want to reset the password based on that access token, is that possible or how do i do this I have even tried asking calude, gpt, deepseek, and all failed at solving this puzzle so for anyone who knows, they are better than the top 3 LLMs
Catto
CattoOP7d ago
To be crystal clear, the exact code i need help with is here
No description
Catto
CattoOP7d ago
somehow the server has to know what session we talking about based on the passed access token
Anton
Anton7d ago
do you know what claims are?
Catto
CattoOP7d ago
no
Anton
Anton7d ago
you should learn that for sure
Catto
CattoOP7d ago
how does that relate to what im doing tho
Anton
Anton7d ago
it has to do with tokens. they actually store information. so might be related
Catto
CattoOP7d ago
so what do they do for me, imagine i use supabase auth login, the user logs in i pass that access token as a cookie for the front end to use whenever it makes any request to the server where does this claim play a part in here
Anton
Anton7d ago
idk how supabase does sessions you can get like the user name from the token maybe it has some info you need to make the session work, I don't know It's an idea
Catto
CattoOP7d ago
true, i never thought of mentioning claims services stuff to the LLMs perhaps that would have given them some thought But actually, i was speaking to th LLM earlier and i think its found a soltuion to my issue will try it out but yea
Anton
Anton7d ago
what are the params to that method? SetSession the empty string and the true you should use named args probably
Catto
CattoOP7d ago
access token and refresh token i only had the access token refresh token i dont even know where id get from tbh, meh
Catto
CattoOP7d ago
No description
Catto
CattoOP7d ago
Heres what i got im gonna be calling some endpoint on supabase directly, and passing my payload and that will update the user so rather than doing it through the supabase client i just do like this might work
Anton
Anton7d ago
you have configured something wrong if that works with the client maybe didn't put in the right base url or app name or something
Catto
CattoOP7d ago
im not sure how you think so why wouldnt that work
Anton
Anton7d ago
well if it works with HttpClient, then your supabase client abstraction doesn't send the requests correctly so it's probably been misconfigured again, assuming rawdog http works
Catto
CattoOP7d ago
well it works idk
Unknown User
Unknown User6d ago
Message Not Public
Sign In & Join Server To View
Catto
CattoOP6d ago
hmhmhm
// Create a new HttpRequestMessage for this specific request
var requestMessage = new HttpRequestMessage(HttpMethod.Put, $"{_config["Supabase:Url"]}/auth/v1/user");

// Add the necessary headers to this specific request
requestMessage.Headers.Add("apikey", _supabaseSettings.ServiceRoleKey);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

// Add the payload
var payload = new
{
password = request.Password
};
requestMessage.Content = JsonContent.Create(payload);

// Send the request
var response = await _httpClient.SendAsync(requestMessage);
// Create a new HttpRequestMessage for this specific request
var requestMessage = new HttpRequestMessage(HttpMethod.Put, $"{_config["Supabase:Url"]}/auth/v1/user");

// Add the necessary headers to this specific request
requestMessage.Headers.Add("apikey", _supabaseSettings.ServiceRoleKey);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

// Add the payload
var payload = new
{
password = request.Password
};
requestMessage.Content = JsonContent.Create(payload);

// Send the request
var response = await _httpClient.SendAsync(requestMessage);
im guessing someting like this will do?
Unknown User
Unknown User6d ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?