Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign up with email and password #14

Open
rymkapro opened this issue Jan 16, 2025 · 6 comments
Open

Sign up with email and password #14

rymkapro opened this issue Jan 16, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@rymkapro
Copy link

rymkapro commented Jan 16, 2025

Bug report

Describe the bug

Calling function sign_up_with_email_and_password always returns an error

sign_up_with_email_and_password(&data.email.to_lowercase(), &data.password, None)
        .await
        .map_err(|e| {
            tracing::error!("Error details: {:?}", e);
            match e {
                supabase_auth::error::Error::AuthError { status, message } => {
                    if status == 200 {
                        tracing::debug!("Signup message: {:?}", message);
                    }
                    APIError::new(status, "Create user")
                        .data(serde_json::from_str(&message).unwrap())
                }
                _ => {
                    tracing::error!("[CreateUser]: supabase create user ({})", e);
                    APIError::internal_server_error(&APIErrorCode::HandlerSinginWithEmail)
                }
            }
        })?;

tracing::error!("Error details: {:?}", e) will show something like that
Error details: AuthError { status: 200, message: "{\"id\":\"ebae4bf5-e...\",\"aud\":\"authenticated\",\"role\":\"authenticated\",\"...}" }

But the user is created successfuly in supabase and receives a confirmation email

It also seems that this function returns not a Session

Thanks!

@rymkapro rymkapro added the bug Something isn't working label Jan 16, 2025
@Proziam
Copy link
Collaborator

Proziam commented Jan 20, 2025

I haven't been able to reproduce this yet, but I will keep this open and poke at it some more.

Typically, that error happens if Supabase is sending a response that can't be parsed into the corresponding struct. My first thought is that there may be some setting in your supabase dashboard that changes the shape of the response.

This is the test running in CI (passes):

#[tokio::test]
async fn sign_up_with_email_test_valid() {
    let auth_client = create_test_client();

    let uuid = uuid::Uuid::now_v7();

    let demo_email = format!("signup__{}@demo.com", uuid);
    let demo_password = "ciJUAojfZZYKfCxkiUWH";

    let data = serde_json::json!({
        "test": format!("test" ),
        "name": format!("test" )
    });

    let options = SignUpWithPasswordOptions {
        data: Some(data),
        ..Default::default()
    };

    let session = auth_client
        .sign_up_with_email_and_password(demo_email.as_ref(), demo_password, Some(options))
        .await
        .unwrap();

    // Wait to prevent running into Supabase rate limits when running cargo test
    let one_minute = time::Duration::from_secs(60);
    thread::sleep(one_minute);

    assert!(session.user.email == demo_email);
    assert!(session.user.user_metadata.name.unwrap() == "test");
    assert!(
        session
            .user
            .user_metadata
            .custom
            .get("test")
            .unwrap()
            .as_str()
            .unwrap()
            == "test"
    )
}

@Raflos10
Copy link
Contributor

If your supabase instance is set up to send confirmation emails on sign up, the /signup endpoint doesn't return a session. It returns a json that looks something like like this

{
  "id": "ba55f99c-a9b2-4ff7-8d63-06992ade459c",
  "aud": "authenticated",
  "role": "authenticated",
  "email": "[[email protected]]",
  "phone": "",
  "confirmation_sent_at": "2025-01-26T17:57:29.271251624Z",
  "created_at": "2025-01-26T17:57:29.255304Z",
  "updated_at": "2025-01-26T17:57:29.277574Z",
  "is_anonymous": false
}

It looks like the javascript client handles this by returning either a session or null, so one solution would be to return None if the confirmation email was sent.

@rymkapro
Copy link
Author

Thanks for your help! I'll close this issue to keep repository clean

@Raflos10
Copy link
Contributor

Thanks for your help! I'll close this issue to keep repository clean

You sure you don't want to wait until the issue is fixed?

@rymkapro
Copy link
Author

Thanks for your help! I'll close this issue to keep repository clean

You sure you don't want to wait until the issue is fixed?

hmm, mb you are right..

@rymkapro rymkapro reopened this Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants