Hey guys, we’re using Kratos to authenticate our u...
# ory-network
c
Hey guys, we’re using Kratos to authenticate our users, but, we can’t deploy our app to production and work correctly with Kratos Cloud. We’re using vercel to deploy a NextJS app, in local we just set the
ORY_SDK_URL
into our
.env.local
file and it work correctly, into our OryCloud configuration we have set the custom ui like the image attached. It works fine, in local all work correctly, but in production, we’re receiving a lot of redirections and never can reach the UI directly into our app. Is there something we should take into account to deploy an app to production? PD.: We’re using a middleware to check if the session exist, if not, we redirect the user to the login flow. Again, in local it work expectedly…
Copy code
// middleware.ts

function redirectToSignInFlow(request: NextRequest) {
  return NextResponse.redirect(
    new URL(`${edgeConfig.basePath}/self-service/login/browser`, request.url)
  );
}

export async function middleware(request: NextRequest) {
  try {
    const headers = new Headers();
    headers.set('Cookie', String(request.headers.get('cookie')));

    const res = await checkSessionEdge(headers);

    if (res.ok) {
      return NextResponse.next();
    }

    return redirectToSignInFlow(request);
  } catch (error) {
    return redirectToSignInFlow(request);
  }
}
The
chekcSessionEdge
method is:
Copy code
import { edgeConfig } from '@ory/integrations/next';

const checkSessionEdge = async (headers: Headers): Promise<Response> =>
  await fetch(
    `${process.env.NEXT_PUBLIC_VERCEL_URL}${edgeConfig.basePath}/sessions/whoami`,
    {
      headers,
    }
  );

export { checkSessionEdge };
m
Hello Ata, Your problem could be related to several things, can you check the following points for me please: 1. Are you sure the cookie is retrievable in your middleware when the user logs in? 2. Are you sure you are setting the right URLs when deploying to Vercel? 3. Are you using a custom domain name? 4. Are you using the ory proxy built into the nextjs example?