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

Return identity upon user registration with email+password #7275

Closed
mitjans opened this issue Apr 29, 2024 · 2 comments
Closed

Return identity upon user registration with email+password #7275

mitjans opened this issue Apr 29, 2024 · 2 comments

Comments

@mitjans
Copy link

mitjans commented Apr 29, 2024

I've followed the Email+Password Auth tutorial and would like to know if it's possible to get the identity id of the user when it registers (before verifying the email).

The code in question is the following in the tutorial:

const registerUrl = new URL("register", EDGEDB_AUTH_BASE_URL);
const registerResponse = await fetch(registerUrl.href, {
  method: "post",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    challenge: pkce.challenge,
    email,
    password,
    provider,
    verify_url: `http://localhost:${SERVER_PORT}/auth/verify`,
  }),
});

After this fetch call, the user is correctly registered in the database, but the fetch response only contains the field verification_email_sent_at. I have created a User type that has a link to ext::auth::Identity and would like to create an entry when the user registers, but I have no way of knowing the identity id of the newly registered user to create an entry of type User.

Here's my type:

type User {
  required name: str;
  required identity: ext::auth::Identity;
}

I'm trying the following after the successful registration:

e.insert(e.default.User, {
  name: body.name,
  identity: // How can I link up to the newly registered user here? 
}

Looking at the code that handles the registration, it looks like EdgeDB should be able to return the identity of the registered user to the client. Is there a reason for not doing it? Something like this:

 response.body = json.dumps(
    {"verification_email_sent_at": (now_iso8601), "identity_id": identity.id}
).encode()
@scotttrinh
Copy link
Contributor

The point of require_verification is that you do not get the Identity and the auth token before the user verifies their email. If you would like access that information, you can set require_verification to false in your provider config. See https://docs.edgedb.com/guides/auth#email-and-password for more details on how to do that.

@mitjans
Copy link
Author

mitjans commented May 21, 2024

But I don't want the auth_token. It makes sense not to get the auth_token until the user verifies their email (especially if require_verification is true).

I've checked and the identity row is created in EdgeDB when the user is created but not verified. I want the ID associated with that user to do some extra work in the backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants