hey. the `updateLoginFlow()` in the TS/JS sdk. doe...
# general
h
hey. the
updateLoginFlow()
in the TS/JS sdk. does that technically do
.toSession()
behind the scenes ?? i don't feel like it does.
Copy code
sdk
    .updateLoginFlow({ flow: flow.id, updateLoginFlowBody: body })
    .then(() => {
      // we successfully submitted the login flow, so lets redirect to the dashboard
      navigate({ to: "/dashboard", replace: true })
    })
    .catch(sdkErrorHandler)
}
simply because the
dashboard.tsx
example has this written:
Copy code
useEffect(() => {
    // we check if the user is logged in by checking if there is a session
    // if no session is found, we redirect to the login page
    sdk
      .toSession()
      .then(({ data: session }) => {
        // we set the session data which contains the user Identifier and other traits.
        setSession(session)
        // Set logout flow
        createLogoutFlow()
      })
      .catch(sdkErrorHandler)
      .catch((error) => {
        // Handle all other errors like error.message "network error" if Kratos can not be connected etc.
        if (error.message) {
          return navigate(`/error?error=${encodeURIComponent(error.message)}`, {
            replace: true,
          })
        }

        // Just stringify error and print all data
        navigate(`/error?error=${encodeURIComponent(JSON.stringify(error))}`, {
          replace: true,
        })
      })
  }
so here's how i understand it works. When being redirected to
/dashboard
after my creds are correct, then the navigate returns back the
session_token
to
dashboard
and the
useEffect()
code runs before the page is loaded, and do the
.toSession()
that then trigger
setSession()
etc.. is that correctly understood?
b
updateLoginFlow should fail if the browser already has a session. useEffect runs slightly after the component is rendered, and re-runs whenever the data in its dependency changes (on the next render).