Hey :slightly_smiling_face: I have a question abo...
# talk-kratos
s
Hey 🙂 I have a question about registration after hook. Based on docs (here and here - section Expand to see an example of all properties of the
ctx
object for a registration flow) - identity should exist at that point in kratos, but from my tests user is not created and I get identity id =
00000000-0000-0000-0000-000000000000
. Is this a known bug? And if so how I can bind kratos user with my internal user entity after registration?
s
Also note that trigger precendence doc says that after action is when " user submits or completes the flow". So when user submits a flow is something different than completes the flow and I'm little bit confused.
@careful-rain-13694 yeah, but I need parse set to true
I need to setup my internal user first and then continue registration
otherwise how can I allow to log into my app (auto login after registration) if not everything is ready, and how to sync that then 😕
c
The issue here is that because having the
response.parse
set to true, it calls the webhook AFTER registration BEFORE creating it in the database, as the webhook response modifies the identity first. (feedback from Ory)
Another option would be creating two different hooks as post-registration.
s
Or putting differently I need both user entities (in kratos and my system) to exist before I allow to login into my app
c
On my side, I used a
parse: false
for a post-registration action and used a post-login hook to ensure the account <> identityId mapping within our internal db
Maybe dealing with an action as "before-login" could help in your case 🤔
s
I see, this looks like a solution, although a bit wired I have to say 😄
at least in my usecase
because the login hook in that case would be just a "checker" to see if post-registartion hook (parse: false) was executed
c
Yes indeed but I don't think there should be a more appropriate / standard way regarding the documentation (as far as I know - which is not that far actually 🙂)
I guess it needs to be tested
playing around with different configurations (
parse
and
ignore
parameters) it may help figuring out the right flow fitting your use-case
s
@careful-rain-13694, I'm gonna test a few setups here, but I'm really grateful for your help and pointing me in the right direction. Thank you so much 🙏
d
hey @silly-belgium-72317 we had the exact same issue, and we solved it with 2 webhooks
the first webhook is configured with:
Copy code
ignore: false
parse: true
This webhook creates the member entity in our internal database, and updates Kratos’s
metadata_public
to add our internal member.id to it, so now we can get our internal member from the kratos identity. The second webhook is configured:
Copy code
ignore: false
parse: false
At this stage the Kratos identity.id now exists, as the entity has been saved to the database (and kratos uses autogenerated IDs). The second webhook updates our member table with the kratos identity ID. So now we have our internal ID stored on kratos’s identity.metadata_public, and we have the Kratos identity ID stored on our member table
s
@dazzling-napkin-4938 how did you solve the issue with user<>identity mapping? Let me show you a flow and what I mean by that: 1. User submits the registration flow 2. Pre registration hook (parse: true, pre identity creation) is sent 3. User is created in my db but the identity id is null, I have email tho 4. 200 is returned 5. Identity is created (in kratos) and there's an id given (identity id) Now there are multiple options but basically, all comes to "linking" user with identity - it can be based on email which is present in both user and identity but I feel this is something that should be avoid because email is "kinda" not contacts. So I thought ok, I need an unique id generated by my backend and store that in identity.private metadata and once user first login into my app and I see that user.identity_id is set to null I get the unique id from private metadata and I match based on this id. This seems to me like a correct flow, but at the same time, it's so tempting to match based on email...
Oh, I started to write but you already answered my question
d
our kratos config looks like this:
Copy code
registration:
      after:
        hooks:
          - hook: web_hook
            config:
              url: <http://example.com/create-member>
              method: POST
              body: <base64://YOUR> BASE 64 STRING
              response:
                ignore: false
                parse: true 
          - hook: web_hook
            config:
              url: <http://example.com/update-kratos-id>
              method: POST
              body: YOUR BASE 64 BODY 
              response:
                ignore: false
                parse: false
s
It look like a flow that is so common that it should be supported out of the box. Another good approach would be if a backend can return an identity.id and kratos uses it, but this requires change on the main kratos schema from uuid to string (identity.id) and with that change I have a single user id in both my and kratos db
s
amazing I had exactly the same problem yesterday. and have the same solution... 🙂
b
This is blocking us as well, where we would expect to get the
identity.id
in a post-registration hook and do the provider-mapping inside our own application.