Hello! I am trying to implement Self Service Login...
# talk-kratos
d
Hello! I am trying to implement Self Service Login in Ory Kratos. I do everything on the client. When submitting the form, I get a 400 (bad request) error. I’m guessing it’s because of the wrong request body. I plan to login via email and password, so I send these fields accordingly: See the screenshot. My question: Which request body should I send? Only object with password and email? But I still get a 400 error and my request is not processed further. I will be grateful for your answers and help ) πŸ™Œ
s
This is the raw json body I send to update login flow, from Postman
Copy code
{
  "identifier": "<mailto:my@email.com|my@email.com>",
  "password": "dsafdsfdsvcxvcxbfddf.21",
  "method": "password"
}
On kotlin, I do this, in case it's of any use to you
Copy code
val withPasswordMethod = UpdateLoginFlowWithPasswordMethod().apply {
            val ui = updateLoginFlowRequest.ui
            method = ui.nodesList.single { it.type == AuthFormNode.NodeType.Submit }.value
            password = ui.nodeWithName(SERIALIZED_NAME_PASSWORD).value
            identifier = ui.nodeWithName(SERIALIZED_NAME_IDENTIFIER).value
        }


val response: SuccessfulNativeLogin = frontendApi.updateLoginFlow(
                updateLoginFlowRequest.id,
                UpdateLoginFlowBody(withPasswordMethod),
                null, //token
                null //cookie
            )
d
Hey @shy-fish-88756 ! Thank you for your help and effort!) I tried to put these fields several times, unfortunately I am getting the same error, 400 bad request : ( `router.push(
/login?flow=${loginFlow.value.id}
)`
.then(() => {
ory.updateLoginFlow({
flow: String(loginFlow.value.id),
updateLoginFlowBody: {
email: '<mailto:admin@dev.pointprism.com|admin@dev.pointprism.com>',
password: 'qwerty.qwerty',
// method: 'POST',
},
})
s
you are using
email
where I use
identifier
. Maybe the error is there and you don't specify the
method
d
@shy-fish-88756 still getting this error (
s
sorry I can't help more I use native flows where you seem to use web. I think you might miss some csrf token, but I'm not a web developer
d
@shy-fish-88756 thank you so much! πŸ™
@shy-fish-88756 oh my gosh, it is working!!! I changed request body from
identifier: email.value,
password: password.value,
method: 'POST',
to
identifier: email.value,
password: password.value,
method: 'password',
csrf_token: loginFlow.value?.ui?.nodes[0]?.attributes?.value
I needed to add
csrf_token
field and change method value ))) Thank you so much, your answer helped me so much πŸ™πŸ˜Š
s
great πŸ‘