Skip to content

How to handle kratos in next js? #1683

Answered by spa5k
spa5k asked this question in Q&A
Aug 25, 2021 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Taking hints from the self-service-node's official example, I moved the kratos initialization part inside the
getServerSideProps, and now it's working and giving results with No csrf errors anymore.

export async function getServerSideProps(context: NextPageContext) {
  const allCookies = context.req.headers.cookie;
  const flowId = context.query.flow;

  if (!flowId) {
    return {
      redirect: {
        destination: `${API_URL}/self-service/login/browser`,
      },
    };
  }

  let flowData: SelfServiceLoginFlow | void;

  if (allCookies && flowId) {
    const data = await kratos
      .getSelfServiceLoginFlow(flowId.toString(), allCookies)
      .then(({ data: flow }) => {
        r…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@spa5k
Comment options

@vinckr
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vinckr
Comment options

Answer selected by spa5k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants