Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- [x] Logout
- [x] Verify one-time token
- [ ] Authorize external OAuth provicder
- [ ] Password recovery
- [x] Password recovery
- [x] Resend one-time password over email or SMS
- [ ] Magic link authentication
- [x] One-time password authentication
Expand Down
36 changes: 36 additions & 0 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ impl std::fmt::Display for LogoutError {

impl std::error::Error for LogoutError {}

#[derive(Serialize)]
struct RecoverRequest<'a> {
email: &'a str,
}

#[derive(Serialize)]
struct PhoneCredentials<'a> {
phone: &'a str,
Expand Down Expand Up @@ -122,6 +127,19 @@ impl Supabase {
.await)
}

/// Sends a password recovery email to the given address.
pub async fn recover_password(&self, email: &str) -> Result<Response, Error> {
let url = format!("{}/auth/v1/recover", self.url);

self.client
.post(&url)
.header("apikey", &self.api_key)
.header("Content-Type", "application/json")
.json(&RecoverRequest { email })
.send()
.await
}

/// Signs up a new user with phone and password.
pub async fn signup_phone_password(
&self,
Expand Down Expand Up @@ -385,6 +403,24 @@ mod tests {
assert_eq!(format!("{}", LogoutError), "bearer token required for logout");
}

#[tokio::test]
async fn test_recover_password() {
let client = client();

let response = match client
.recover_password("test@a-rust-domain-that-does-not-exist.com")
.await
{
Ok(resp) => resp,
Err(e) => {
println!("Test skipped due to network error: {e}");
return;
}
};

let _status = response.status();
}

#[tokio::test]
async fn test_signup_phone_password() {
let client = client();
Expand Down