Hi ! is it possible to generate a session through ...
# talk-kratos
b
Hi ! is it possible to generate a session through the admin api? I'm trying to create a user during a purchase process and have the user be logged in right away. I need to set some metadata_admin on the user while creating it so I don't think using the regular register flow from within javascript would work very well Creating the user via "POST /admin/identities" seems fine but I can't seem to find an endpoint to create a session for this user?
c
Creating a session for another user programatically seems really strange, what exactly are you trying to achieve? If you want to create metadata for an identity, you don't need the user session, you should even be able to set the metadata in the original POST. If you want the user to create the identity and then have your backend update the metadata, I would use a webhook to set the metadata, so the user can still follow the regular registration flow - for example the registration.after action - it's all documented here: https://www.ory.sh/docs/kratos/hooks/configure-hooks#web-hooks
If you want your webhook to also sign the user in, the default ory webhook that does this is located here: https://github.com/ory/kratos/blob/master/selfservice/hook/session_issuer.go - so you can look at that code and try to replicate it 🙂